In SAS, I have a data set similar to the one below.
ID TRACT meanFA sdFA medianFA
1 t01 0.56 0.14 0.56
1 t02 0.53
You need 2 transposes. Transpose, use a data step to update then _NAME_
variable, and then transpose again;
proc transpose data=tract out=tract2;
by id tract;
run;
data tract2;
format _name_ $32.;
set tract2;
_name_ = strip(tract) || "_" || strip(_name_);
run;
proc transpose data=tract2 out=tract3(drop=_name_);
by id;
/*With no ID statement, the _NAME_ variable is used*/
var col1;
run;
Using example data from this duplicate question.
You can also just do this with a data step.
First, put the maximum sequence number into a macro variable.
proc sql;
select
max(sequence_no) into : maxseq
from
have
;
quit;
Create arrays for your new variables, setting the dimensions with the macro variable. Then loop over each visit, putting the events and notes into their respective variables. Output 1 line per visit.
data want(drop=sequence_no--notes);
do until (last.visit_no);
set have;
by id visit_no;
array event_ (&maxseq);
array notes_ (&maxseq) $;
event_(sequence_no)=event_code;
notes_(sequence_no)=notes;
end;
output;
run;
Double transpose is how you get to that. Get it to a dataset that has one row per desired variable per ID, so
ID=1 variable=t01_meanFA value=0.56
ID=1 variable=t01_sdFA value=0.14
...
ID=2 variable=t01_meanFA value=0.72
...
Then transpose using ID=variable and var=value (or whatever you choose to name those columns). You create the intermediate dataset by creating an array of your values (array vars[3] meanFA sdFA medianFA;
) and then iterating over that array, setting variable name to catx('_',tract,vname(vars[n]));
(vname
gets the variable name of the array element).