fyfzhdsfdx 发表于 2012-10-11 19:42 
刚才的回复有问题,不好意思啊,我知道name1数据集的作用。现在的程序可以,我试过,结果正确,不过有警告 ...
我这边运行没有警告:
1 data name;
2 set sashelp.class end=last;
3 keep name;
4 if last then call symputx("nobs",_n_);
5 run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.NAME has 19 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.29 seconds
cpu time 0.01 seconds
6
7 proc transpose data=name out=name1;
8 var name;
9 run;
NOTE: There were 19 observations read from the data set WORK.NAME.
NOTE: The data set WORK.NAME1 has 1 observations and 20 variables.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds
10
11 data name2;
12 array name(6) $;
13 array col(&nobs) $ col1-col&nobs;
14 set name1;
15 do i=1 to &nobs-5;
16 do j=0 to 5;
17 name(j+1)=col(i+j);
18 end;
19 output;
20 end;
21 keep name:;
22 stop;
23 run;
NOTE: There were 1 observations read from the data set WORK.NAME1.
NOTE: The data set WORK.NAME2 has 14 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.10 seconds
cpu time 0.04 seconds
Keep name:; 这句表示keep所有以“name”开头的变量。相当于:
keep name1 name2 name3 name4 name5 name6; /*将所有变量一一列出*/
keep name1-name6; /*表示keep name1, name2,.. 一直到 name6*/
keep name1--name6; /*按照变量在数据集中的位置keep name1 和name6之间的所有变量,对名字没有要求*/