SAS中文论坛

标题: 新手困惑,请高手帮忙~ [打印本页]

作者: shiyiming    时间: 2008-9-15 18:38
标题: 新手困惑,请高手帮忙~
data a;
input id time col;
cards;
2 1 9
2 2 15
2 3 16
3 1 4
3 3 9
;
proc sort;
by id time;
run;
data b;
set a;
by id time;
retain col1 col2;
array dd(3) col1-col3;
dd(time)=col;
if last.id then do;
  output;
  do time=1 to 3;
    dd(time)=.;
  end;
end;
run;
proc print;
run;
初学sas,这段程序弄不太懂,麻烦高手帮我加下注释...不胜感激!!!
作者: shiyiming    时间: 2008-9-16 14:46
标题: Re: 新手困惑,请高手帮忙~
我也是新手,如果解释不对的一起讨论
[code:3ka2rwix]
/*创建了一个data set*/
data a;
input id time col;
cards;
2 1 9
2 2 15
2 3 16
3 1 4
3 3 9
;
/*按照id和time进行分组*/
proc sort;
by id time;
run;
/*构造一个名为b的data set*/
data b;
set a;
by id time;
/*retain 表示在下一次迭代的时候保留上次的值*/
retain col1 col2;
/*构造了一个数据,col1 col2 col3*/
array dd(3) col1-col3;
/*设置下标等于time标量的值,确值为col标量的值*/
dd(time)=col;
/*last.id表示按照id分组后,取到该组的最后一项时*/
if last.id then do;
        output;/*输出*/
        do time=1 to 3;/*循环,把数组的值设为"."*/
                dd(time)=.;
        end;
end;
run;
proc print;
run;

[/code:3ka2rwix]




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2