BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JBCooney
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Try

proc transpose data=long out=wide prefix=var;

by id trt sex notsorted;

id time;

var var;

run;

PG

PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

Try

proc transpose data=long out=wide prefix=var;

by id trt sex notsorted;

id time;

var var;

run;

PG

PG
JBCooney
Calcite | Level 5

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!!!

Jagadishkatam
Amethyst | Level 16

Alternatively by arrays in datastep

Thanks,

Jag

Thanks,
Jag
JBCooney
Calcite | Level 5

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

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1159 views
  • 2 likes
  • 3 in conversation