将SAS数据集重新格式化为多个观察结果

时间:2014-02-06 15:34:56

标签: formatting dataset sas

我正在尝试重新格式化SAS中的数据集,我将其作为csv输出。目前的格式为:

Type, Name, data1, data2, data3…
Dog, retriever, 20, 40, 60…
Dog, corgi, 10, 30, 50…
Cat, Persian, 15, 25, 35…
Cat, stray, 1, 2, 3…

我正试图以格式获取它:

Dog, retriever, data1, 20
Dog, retriever, data2, 40
Dog, retriever, data3, 60
Dog, Corgi, data1, 10
Dog, corgi, data2, 30
Dog, corgi, data3, 50
Cat, Persian, data1, 15
Cat, Persian, data2, 25
Cat, Persian, data3, 35
Cat, Siamese, data1, 1
Cat, Siamese, data2, 2
Cat, Siamese, data3, 3

你知道在SAS中解决这个问题的最佳方法吗?

谢谢

1 个答案:

答案 0 :(得分:1)

使用proc转置,如下所示:

PROC TRANSPOSE DATA = ...
    OUT=...
    NAME=ValueSource
    LABEL=ValueDescription
    ;
    BY type name;
    ID <a column with hte same value for all your observations>;
    VAR data1 data2 data3;
RUN;