SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1980|回复: 1
打印 上一主题 下一主题

求助大神把我的笨笨的手动code改成macro,do loop...

[复制链接]

1

主题

1

帖子

5

积分

新手上路

Rank: 1

积分
5
跳转到指定楼层
楼主
发表于 2015-7-3 22:34:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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;

分享到:  微信微信
收藏收藏
回复

使用道具 举报

11

主题

49

帖子

267

积分

中级会员

Rank: 3Rank: 3

积分
267
沙发
发表于 2015-7-31 10:46:06 | 只看该作者
说清楚有你什么(最好是给个有特征的sample data), 然后说明白你最终想要得到什么(也最好给个结果的样子),否则,别人不太可能花大把时间先去猜你在说什么,然后再去帮你解决问题。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2024-4-20 15:28 , Processed in 0.132266 second(s), 21 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表