BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Amanda_Lemon
Quartz | Level 8
@novinosrin and @Reeza, thank you both! I understood both approaches. Thanks again for your help!
Amanda_Lemon
Quartz | Level 8
One more question -- is there a similarly easy way to do the reverse procedure, i.e., transform a wide data set into a tall one?
Reeza
Super User

PROC TRANSPOSE! It goes both ways 😉

 

Long to Wide

https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/

 

Wide to Long

https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/

 


@Amanda_Lemon wrote:
One more question -- is there a similarly easy way to do the reverse procedure, i.e., transform a wide data set into a tall one?

 

 

Amanda_Lemon
Quartz | Level 8

It works! Thank you!!

 

A follow-up question: I am not quite sure which of my variables are attributes of a person (i.e., don't vary within a person between Time 1 and Time 2) and which are attributes of a test (different values for Time 1 and Time 2 for the same person). Is there an easy way to find out which variables are which? 

 

The best option I found so far is to split the file into two: one file with Time 1 values and another file with Time 2 values, and then use proc compare. It gives me a table with unequal values... but I thought maybe there is a way that I can get a LIST of variables with unequal values and a LIST of variables with equal values so that it's easier to copy-paste in proc transpose? (I have about 600 variables, so I am really looking to automatize this process...).

 

Any ideas would be highly appreciated!

Reeza
Super User

Working on a very similar problem at the moment. I test it out by checking if the max=min for the variables in question across the person ID. 

This is easier done in SQL than a data step because PROC SQL will allow the max/min functions to be used on character variables. 

 

 

novinosrin
Tourmaline | Level 20

You could play with this approach

 

proc means data=have noprint;
by id;
var _all_;
output out=want(drop= _:) std=;
run;
proc transpose data=want(obs=1) out=w;
run;
proc sql;
select _name_ into :by_group separated by ' '
from w
where col1 = 0;

select _name_ into :tranpose_var separated by ' '
from w
where col1 ne  0;

quit;
/*by group and transpose lists*/
%put &by_group;
%put &tranpose_var;
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 20 replies
  • 3535 views
  • 3 likes
  • 3 in conversation