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

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!

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

 
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;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

 
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;
accintron
Obsidian | Level 7

Thank you! Didn't realize I could use an ID statement to call Quarter_Year values. 

Reeza
Super User
Seems like a straight forward proc transpose. Use ID and IDLABEL to specify the naming variable.
You may need to sort first if you have more than one site id.

proc transpose data=have out=want;
by site_id;
var s1_6_tot;
id quarter_year;
idlabel quarter_year;
run;
accintron
Obsidian | Level 7

Thank you Reeza! This was more straight forward then I thought it would be. Thanks for your input as well 🙂

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 638 views
  • 2 likes
  • 3 in conversation