有点棘手的问题。我需要系统地分组,排序和创建新的数据行的方法。有三个4级分层(c1,c2,c3,c4)和一个"分数"每次迭代分层的价值。这有点难以表达,所以我会给你HAVE和WANT表
以下是数据表格,便于操作。
data HAVE;
input CLASS $ FUR_COLOR $ FAMILY $ SPECIES $ NO_IN_CAPTIVITY;
datalines;
MAMMAL BLACK WHALE KILLER_WHALE 2
MAMMAL BLACK FELINE PUMA 3
MAMMAL BLACK APE CHIMP 5
MAMMAL BLACK APE GORILLA 3
MAMMAL BLACK APE BONOBO 3
MAMMAL RED APE ORANGUTAN 2
;
RUN;
data WANT;
input C1 $ C2 $ C3 $ C4;
datalines;
MAMMAL . BLACK .
MAMMAL WHALE KILLER_WHALE 2
MAMMAL . BLACK .
MAMMAL FELINE PUMA 3
MAMMAL . BLACK .
MAMMAL APE CHIMP 5
MAMMAL APE GORILLA 3
MAMMAL APE BONOBO 3
MAMMAL . RED .
MAMMAL APE ORANGUTAN 2
;
RUN;
答案 0 :(得分:1)
你可以这样使用PROC SQL
和UNION ALL
:
PROC SQL;
CREATE TABLE want AS
SELECT
C1, C2, C4, SCORE
FROM
have
UNION ALL
SELECT
C1, NULL, C3, NULL
/* If your version does not support NULL, use '' */
FROM
have;
QUIT;
输出:
答案 1 :(得分:1)