I am attempting to reshape the following long data set to a wide data set and retain individual identifying information. The data set has missing values. I can transpose the repeating VAR values but can't seem to carry the TRT and SEX values with the transposition.
Long Data Set
ID TIME VAR TRT SEX
01 1 1150 1 M
01 2 1158 1 M
02 1 1201 1 F
02 2 1236 1 F
02 3 1240 1 F
03 2 1358 2 M
04 1 1285 2 F
04 2 1280 2 F
04 3 1290 2 F
Desired Wide Data Set
ID VAR1 VAR1 VAR3 TRT SEX
01 1150 1158 . 1 M
02 1201 1236 1240 1 F
03 . 1358 . 2 M
04 1285 1280 1290 2 F
Scoured previous posts and could not find a similar example. Thanks for any assistance.
Try
proc transpose data=long out=wide prefix=var;
by id trt sex notsorted;
id time;
var var;
run;
PG
Try
proc transpose data=long out=wide prefix=var;
by id trt sex notsorted;
id time;
var var;
run;
PG
Dear PGStats,
I forgot to specify sex $ when I ran the example in SAS UE. Nevertheless, your suggestion scaled up nicely to my larger data set. The NOTSORTED option in the BY statement seems to be what I was missing.
Many thanks!!!
Alternatively by arrays in datastep
Thanks,
Jag
Jag,
Thanks so much for your guidance. After some study your reply has really helped me to better understand array processing in SAS. Very powerful.
Best,
John
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.