我有如下数据,并希望最终每周汇总数据。第一步是为客户创造周。
data have;
input ID start :mmddyy10. channel type $;
datalines;
1 05/21/2009 143 radio
1 05/30/2009 157 television
2 01/01/2011 45 television
2 01/09/2011 53 computerRadio
;;;;
run;
我希望每个ID都有自己的第一周,以便数据看起来像这样
data want;
input ID start :mmddyy10. channel type $ week;
datalines;
1 05/21/2009 143 radio 1
1 05/30/2009 157 television 2
2 01/01/2011 45 television 1
2 01/09/2011 53 computerRadio 2
;;;;
run;
在SAS中执行此操作,因此proc sql是一个选项,也是一个非常受欢迎的选项。提前致谢
答案 0 :(得分:-1)
请尝试以下操作。
proc sort data=have;
by id start;
run;
data want;
set have;
by id start;
retain week;
if first.id then week = 1;
else week = week + 1;
run;