data have;
input event_name :$32. stid $ income $ educ $ sex $ race $ healthp $ ht wt sbp dbp smoke $;
cards;
baseline 100 1 2 1 1 5 66 140.1 144 98 1
year_2 100 1 2 1 1 4 66 150.1 144 98 1
baseline 200 3 3 2 4 3 62.5 130.2 121 73 2
year_2 200 3 3 2 4 2 62.5 125.8 120 86 2
baseline 300 1 4 1 2 1 64 150.1 129 77 2
year_2 300 1 4 1 2 3 64 145.6 114 74 2
;
proc sort data=have;
by stid event_name;
run;
proc transpose data=have(obs=0) out=vname;
var _all_;
run;
proc sql;
create table level as
select *
from (select distinct event_name from have),
(select * from vname where lowcase(_name_) not in ('stid' 'event_name'))
order by 1;
quit;
data _null_;
set level end=last;
by event_name;
if _n_=1 then call execute('data want;merge ');
if first.event_name then call execute(catt('have(where=(event_name="',event_name,'") rename=('));
call execute(catt(_name_,'=',_name_,'_',event_name));
if last.event_name then call execute('))');
if last then call execute(';by stid;drop event_name;run;');
run;
... View more