|
或者用宏
data test;
input id year;
cards;
1 2001
1 2003
1 2005
2 2002
2 2004
2 2007
;
run;
proc sql noprint;
create table sort as
select distinct id,max(year) as max,min(year) as min from test group by id;
quit;
data _null_;
set sort;
call symputx('nobs',_n_);
call symputx('id'||strip(put(_n_,best.)),_n_);
call symputx('max'||strip(put(_n_,best.)),max);
call symputx('min'||strip(put(_n_,best.)),min);
run;
%macro test;
data want;
retain id;
%do i=1 %to &nobs;
id=&&id&i;
%do j=&&min&i %to &&max&i;
year=&j;output;
%end;
%end;
run;
%mend;
%test;
|