cc11cc11 发表于 2010-2-17 21:26 
我说得不清楚啊?
te.file_list数据集有个字段名为sc,里面有4条观测。宏out以sc为参数被程序调用。
我的意思是当我调用前面一段代码,名为out的宏只会运行一次。按照我的理解,sas程序内置循环,引入数据集的话,程序将会自动循环n次(n=观测数)。
而调用后面的一段代码,out宏会运行4次。
且这两者中方法有个共同的特点:都是将te.file_list里最后一条记录的sc字段存入name宏变量,以致于我不能逐条分析每个观测的sc值。
我的问题是,怎么循环取到每条观测的各个字段值?
Here is the one. But you need to understand it by reading macro manual. Do NOT learn macro before you have solid data step programming experience.
HTH
1 %macro out(out=);
2 %put out="&out";
3 %mend;
4
5 data t1;
6 do i = 1 to 4;
7 output;
8 end;
9 run;
NOTE: The data set WORK.T1 has 4 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.56 seconds
cpu time 0.06 seconds
10
11 data _null_;
12 set t1;
13 call execute('%out(out='||put(i,5.)||')');
14 run;
out="1"
out="2"
out="3"
out="4"
NOTE: There were 4 observations read from the data set WORK.T1.
NOTE: DATA statement used (Total process time):
real time 0.20 seconds
cpu time 0.04 seconds
NOTE: CALL EXECUTE routine executed successfully, but no SAS statements were generated.