How about: data have;
input id $ year month var;
cards;
ID-1 2000 1 20
ID-1 2000 4 30
ID-1 2002 6 40
ID-1 2004 6 40
ID-1 2006 6 40
ID-2 1990 1 50
ID-2 2000 1 60
ID-3 1999 2 70
;
run;
data have;
set have;
flag+dif(year) ;
if id ne lag(id) then flag=1;
run;
data _null_;
set have end=last;
if _n_ eq 1 then call execute('data want; ');
call execute(cats('id="',id,'";','year=',year,';','month=',month,';','var=',var,';'));
call execute(cats('var',flag,'_',month,'=',var,';output;call missing(of _all_);'));
if last then call execute('run;');
run;
proc sql noprint;
select name into : list separated by ' '
from dictionary.columns
where libname='WORK' and memname='WANT' and upcase(name) like 'VAR%~_%' escape '~'
order by input(scan(name,1,' ','kd'),best8.),input(scan(name,2,' ','kd'),best8.) ;
quit;
%put &list;
data want;
retain id year month var &list;
set want;
run;
proc stdize data=want out=want reponly missing=0;
var &list;
run;
Ksharp
... View more