若你已知所有可能的ID值,可以在一个数据步内完成, 假如ID值为1-216。
data d1 d2 d3 .... d206;
set olddata;
select(id);
when(1) output d1;
when(2) output d2;
...
when(216) output d216;
otherwise put "ERROR: other ID value found ID=" ID;
end;
run;
若嫌太长可有宏;
%macro tmp;
proc sql;
select distinct id into: allid separated by '|'
from olddata;
%let nid=&sqlobs;
quit;
data %do i=1 %to &nid;d&i %end;;
set olddata;
select(id);
%do i=1 %to &nid;
%let id=%scan(&allid,&i,|);
when(&id) output d&i;
%end;
otherwise put "ERROR: other ID value found ID=" ID;
end;
run;
[quote="sun59338":8heip1xe]若你已知所有可能的ID值,可以在一个数据步内完成, 假如ID值为1-216。
data d1 d2 d3 .... d206;
set olddata;
select(id);
when(1) output d1;
when(2) output d2;
...
when(216) output d216;
otherwise put "ERROR: other ID value found ID=" ID;
end;
run;
若嫌太长可有宏;
%macro tmp;
proc sql;
select distinct id into: allid separated by '|'
from olddata;
%let nid=&sqlobs;
quit;
data %do i=1 %to &nid;d&i %end;;
set olddata;
select(id);
%do i=1 %to &nid;
%let id=%scan(&allid,&i,|);
when(&id) output d&i;
%end;
otherwise put "ERROR: other ID value found ID=" ID;
end;
run;