RobertBarro 发表于 2010-3-15 00:14 
谢谢大虾。。。
1)我的数据结构:id variables, startdate, enddate, 一系列计算变量形如x200412-x200712, y200412-y200712 etc. 基本样是横表:one observation with lots of variables at different time points.
2) 我需要根据输入的一个宏变量 &prespan,与intck('month',startdate,enddate)做比较,取最小值记为&span。然后取所有startdate时点的x,y 等算出一个z@startdate, 再移动到x@startdate+1,y@startdate+1算出z@startdate+1, 一直到z@startdate+&span为止。
3)因为我的变量名也希望用startdate,startdate+1....startdate+&span的形式结尾,所以我用了宏do循环,用intnx计算出与startdate距离i个月的日期,然后取year and month做变量名后缀,因为是在一个循环里,所以call symput与下面对宏变量的引用不能分开。我要是用%let aa=%sysfunc(intnx('month',startdate,&i.))来定义第一个宏变量,它又说startdate不是个数字(而实际上是一个日期了)。
我希望表示清楚了。调这个程序一天了,都快绝望了。。。。
多谢多谢
I am not sure what exactly you want. The following example may help.
196 data test;
197 array xdt(10) ;
198 do s='23jun2009'd to '3apr2010'd by 30;
199 i+1;
200 xdt(i)=s;
201 end;
202 drop i s;
203 run;
NOTE: The data set WORK.TEST has 1 observations and 10 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
204
205 proc print;
206 format _all_ yymmdd10.;
207 run;
NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
208
209 %let span=5;
210 data _null_;
211 set test;
212 array xdt(*) xdt:;
213 do j=1 to dim (xdt);
214 do i=0 to &span;
215 call symputx(catt(vname(xdt(j)),'_',i) ,intnx('month',xdt1,i));
216 end;
217 end;
218 call symputx('n', dim(xdt));
219 stop;
220 run;
NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
221
222 %macro showit(dummy);
223 %do i = 1 %to &n;
224 %do j=1 %to &span;
225 %put >>>>xdt&i._&j %sysfunc(putn(&&xdt&i._&j, yymmdd10.))
225! %sysfunc(year(&&xdt&i._&j)) %sysfunc(month(&&xdt&i._&j))<<<<;
226 %end;
227 %end;
228 %mend;
229
230 %showit(dummy)
>>>>xdt1_1 2009-07-01 2009 7<<<<
>>>>xdt1_2 2009-08-01 2009 8<<<<
>>>>xdt1_3 2009-09-01 2009 9<<<<
>>>>xdt1_4 2009-10-01 2009 10<<<<
>>>>xdt1_5 2009-11-01 2009 11<<<<
>>>>xdt2_1 2009-07-01 2009 7<<<<
>>>>xdt2_2 2009-08-01 2009 8<<<<
>>>>xdt2_3 2009-09-01 2009 9<<<<
>>>>xdt2_4 2009-10-01 2009 10<<<<
>>>>xdt2_5 2009-11-01 2009 11<<<<
>>>>xdt3_1 2009-07-01 2009 7<<<<
>>>>xdt3_2 2009-08-01 2009 8<<<<
>>>>xdt3_3 2009-09-01 2009 9<<<<
>>>>xdt3_4 2009-10-01 2009 10<<<<
>>>>xdt3_5 2009-11-01 2009 11<<<<
>>>>xdt4_1 2009-07-01 2009 7<<<<
>>>>xdt4_2 2009-08-01 2009 8<<<<
>>>>xdt4_3 2009-09-01 2009 9<<<<
>>>>xdt4_4 2009-10-01 2009 10<<<<
>>>>xdt4_5 2009-11-01 2009 11<<<<
>>>>xdt5_1 2009-07-01 2009 7<<<<
>>>>xdt5_2 2009-08-01 2009 8<<<<
>>>>xdt5_3 2009-09-01 2009 9<<<<
>>>>xdt5_4 2009-10-01 2009 10<<<<
>>>>xdt5_5 2009-11-01 2009 11<<<<
>>>>xdt6_1 2009-07-01 2009 7<<<<
>>>>xdt6_2 2009-08-01 2009 8<<<<
>>>>xdt6_3 2009-09-01 2009 9<<<<
>>>>xdt6_4 2009-10-01 2009 10<<<<
>>>>xdt6_5 2009-11-01 2009 11<<<<
>>>>xdt7_1 2009-07-01 2009 7<<<<
>>>>xdt7_2 2009-08-01 2009 8<<<<
>>>>xdt7_3 2009-09-01 2009 9<<<<
>>>>xdt7_4 2009-10-01 2009 10<<<<
>>>>xdt7_5 2009-11-01 2009 11<<<<
>>>>xdt8_1 2009-07-01 2009 7<<<<
>>>>xdt8_2 2009-08-01 2009 8<<<<
>>>>xdt8_3 2009-09-01 2009 9<<<<
>>>>xdt8_4 2009-10-01 2009 10<<<<
>>>>xdt8_5 2009-11-01 2009 11<<<<
>>>>xdt9_1 2009-07-01 2009 7<<<<
>>>>xdt9_2 2009-08-01 2009 8<<<<
>>>>xdt9_3 2009-09-01 2009 9<<<<
>>>>xdt9_4 2009-10-01 2009 10<<<<
>>>>xdt9_5 2009-11-01 2009 11<<<<
>>>>xdt10_1 2009-07-01 2009 7<<<<
>>>>xdt10_2 2009-08-01 2009 8<<<<
>>>>xdt10_3 2009-09-01 2009 9<<<<
>>>>xdt10_4 2009-10-01 2009 10<<<<
>>>>xdt10_5 2009-11-01 2009 11<<<<