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 🙂
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.