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

I am relatively new to SAS.  I have transposed from long to broad with indicator variables, but I can't figure out how to transpose with only two columns of data.  Seems embarrassingly easy, but nothing seems to work.  Any advice?  Many thanks. I have two observations for each subject that are not identified by anything other than the value of the variable.  Would like a dateset with each of the two values for each subject in a separate column.  Thank you!! Anissa

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @anissak1 

 

Does this code correspond to your need?

NB: you can avoid the PROC SORT step if the dataset is already sorted by USUBJID.

 

All the best,

proc sort data=have out=have_sorted;
	by usubjid;
run;

proc transpose data=have_sorted out=want (drop=_:) prefix=ftstresn;
	var ftstresn;
	by usubjid;
run;

View solution in original post

6 REPLIES 6
ghosh
Barite | Level 11

what have you tried?

 

Care to provide the data in text rather than as an image? 

anissak1
Obsidian | Level 7

Thanks for the reply.  I got the solution!  I think I must have just been making a stupid error with my code and perhaps it was not sorted correctly prior to the transpose procedure.

Kurt_Bremser
Super User

Please post example data in a data step with datalines, and show the code you tried; use the "little running man" for posting code. In case of ERRORs or WARNINGs or any unexpected outcome, post the log with the {i} button.

anissak1
Obsidian | Level 7

Thank you for the reply!  The code provided by the other user worked.  I think it was a matter of my data not being sorted correctly.  As you seem to be a super user, do you have ideas on a (paid) tutor I might sign up with for help to work with directly in the next few weeks?  I'm working on a clinical dataset for a masters thesis that is pretty complicated and could use some ongoing assistance.  Should I post a note for such help on a board perhaps?  Thanks for the guidance!

ed_sas_member
Meteorite | Level 14

Hi @anissak1 

 

Does this code correspond to your need?

NB: you can avoid the PROC SORT step if the dataset is already sorted by USUBJID.

 

All the best,

proc sort data=have out=have_sorted;
	by usubjid;
run;

proc transpose data=have_sorted out=want (drop=_:) prefix=ftstresn;
	var ftstresn;
	by usubjid;
run;
anissak1
Obsidian | Level 7

Thank you!!  That worked.  I have no idea what I did differently with my previous code.  But had been coding all day so perhaps it was just a stupid error.  I appreciate the guidance!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 586 views
  • 1 like
  • 4 in conversation