SAS Transpose和Summarize条目

时间:2014-07-16 18:37:44

标签: sas

我有一个按时间和类型定量值的数据集。我希望以不同的方式总结这些内容,以便我可以看到按类型划分的percntage故障。这是数据集:

    data have;
    input loc $ prod $ time $ type $ total;
cards;
L1 P1 1 xxx 10
L1 P1 1 yyy 30
L1 P1 1 yyy 60
L1 P2 1 xxx 20
L1 P1 2 xxx 25
L1 P2 2 yyy 60
;
run;

我想结束这样的事情:

loc   prod    type  time1 time2 
L1    P1      xxx   .1    1       
L1    P1      yyy   .9    0       
L1    P2      xxx   1     0
L1    P2      yyy   0     1        

我想这会需要某种类型的数组,但是我在解决如何正确使用语法方面遇到了麻烦。我也认为也许proc报告可能有用,但不确定。我需要将输出作为数据集。

感谢您的帮助。

PYLL

1 个答案:

答案 0 :(得分:1)

我会把它放在一个我认为你想要的答案中。

proc sort data=have;
by loc prod;
run;

proc freq data=have noprint;
by loc prod;
tables time*type /out=statout outpct;
weight total;
run;

proc sort data=statout;
by loc prod type;
run;

proc tranpose data=statout out=statout2;
by loc prod type;
id time;
var pct_row;
run;