如果是这个意思,那么你的代码稍加改动就可以了。
- data e;
- set d;
- array x(3);
- do j=1 to 3;/*这里做了修改,数组是不认X(0)的*/
- do i=1 to 18;
- if col0=1972+18*j+i then do;
- x(j)=col1;
- output;/*记得要输出*/
- end;
- end;
- end;
- run;
复制代码
但是这种方法不可取,每读取一个观测,都要循环3*18次,判断3*18次,效率不高。
我自己写了个
data a1(rename=(col1=x1)) a2(rename=(col1=x2)) a3(rename=(col1=x3));
set a;
if _n_<=18 then output a1;
else if _n_<=36 then output a2;
else output a3;
run;
proc sql;
create table test as
select * from a1
outer union corr
select * from a2
outer union corr
select * from a3;
quit;
当然如果要批量的话,你可以改成宏, 希望对你有帮助。