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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.