I'm wondering if there is a way to transpose two variables at once using proc transpose... but one variable would essentially be transposed as the column names... Or can you utilize prefix= to call on an existing variable to name the columns?
My data looks like so:
Site_ID S1_6_tot Quarter_Year
1 35 Q1 2017
1 45 Q2 2017
1 81 Q3 2017
1 126 Q4 2017
Essentially I would like the pertinent Quarter Year to be the name of the column and have the S1_6_tot number the column value like:
Site_ID Q1_2017 Q2_2017 Q3_2017 Q4_2017
1 35 45 81 126
Thanks!
data have;
input Site_ID S1_6_tot Quarter_Year & $15.;
cards;
1 35 Q1 2017
1 45 Q2 2017
1 81 Q3 2017
1 126 Q4 2017
;
proc transpose data=have out=want(drop=_name_);
by site_id;
var S1_6_tot;
id Quarter_Year;
run;
data have;
input Site_ID S1_6_tot Quarter_Year & $15.;
cards;
1 35 Q1 2017
1 45 Q2 2017
1 81 Q3 2017
1 126 Q4 2017
;
proc transpose data=have out=want(drop=_name_);
by site_id;
var S1_6_tot;
id Quarter_Year;
run;
Thank you! Didn't realize I could use an ID statement to call Quarter_Year values.
Thank you Reeza! This was more straight forward then I thought it would be. Thanks for your input as well 🙂
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.