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
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;
what have you tried?
Care to provide the data in text rather than as an image?
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.
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.
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!
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;
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!
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.