SAS中文论坛
标题: 求助大神把我的笨笨的手动code改成macro,do loop... [打印本页]
作者: seashore1987 时间: 2015-7-3 22:34
标题: 求助大神把我的笨笨的手动code改成macro,do loop...
proc sql noprint;
create table ds as
select * from all (keep=_NAME_ Col1-Col17 mom1) Comment: here is col1-col17, but when the "concyear" and concmonth changes, it
inner join b changes,too
on all.mom1=b.mom
where b.month=2 and b.cyear=1987; Comment: I have from 02/1987 to 12/2013, that's why I need easier way.
quit;
data ds1;
set ds;
array col{3} col15-col17; Comment: I only need 3 columns here. But now is 1987/02, if it is 1987/03, then I need
array post{3} post1-post3; col16-col18, etc.
do i=1 to dim(col);
post(i) = col(i);
end;
run;
data ds2;
set ds1;
array col{10} col5-col14; Comment: I need 10 columns totally here. now is col5-col14, if it is 1987/03, then it is
array g{10} g1-g10; col6-col15, etc.
do i=1 to dim(col);
g(i) = col(i);
end;
run;
data ds3; Comment: Actually I need 24 columns as maximum, but here I have already reached
set ds2;
array col{4} col1-col4; minimum, it will increase as the date increase. For example, 1987/03 will have col1-col5,
array pc{4} pc1-pc4; 1987/04 will have col1-col6. When it reaches 24 column as col1-col24, the next month will
do i=1 to dim(col); match col2-col25, and the count of column doesn't change any more
pc(i) = col(i);
end;
run;
data ds;
set ds3;
drop col1-col17 i; drop total number of the old "col" name
run;
作者: gogotiger 时间: 2015-7-31 10:46
说清楚有你什么(最好是给个有特征的sample data), 然后说明白你最终想要得到什么(也最好给个结果的样子),否则,别人不太可能花大把时间先去猜你在说什么,然后再去帮你解决问题。
欢迎光临 SAS中文论坛 (https://mysas.net/forum/) |
Powered by Discuz! X3.2 |