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

I always find it very difficult to transpose tables. In my data, I have values for each month given in a separate column. I would like to make 2 columns out of this, one with the month name, the other with the value from the column. Just like in the example.

Before

data example;
   input country $ company $ type $ jan feb mar apr;
   datalines;
US Sico A 12 15 18 20
US Polo B 8 7 24 25
UK Sico B 6 5 5 4
UK Vax A 16 20 22 24
;

After

data example;
   input country $ company $ type $ month $ prod;
   datalines;
US Sico A jan 12
US Sico A feb 15
US Sico A mar 18
US Sico A apr 20
US Polo B jan 8
US Polo B feb 7
US Polo B mar 24
US Polo B apr 25
;
*and so on

Can you help me with this transposition?

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data example;
   input country $ company $ type $ jan feb mar apr;
   datalines;
US Sico A 12 15 18 20
US Polo B 8 7 24 25
UK Sico B 6 5 5 4
UK Vax A 16 20 22 24
;

proc transpose data=example out=want(rename=( _name_=month col1=prod));
  by country company type notsorted;
  var jan--apr;
 run;
 

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20
data example;
   input country $ company $ type $ jan feb mar apr;
   datalines;
US Sico A 12 15 18 20
US Polo B 8 7 24 25
UK Sico B 6 5 5 4
UK Vax A 16 20 22 24
;

proc transpose data=example out=want(rename=( _name_=month col1=prod));
  by country company type notsorted;
  var jan--apr;
 run;
 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1 reply
  • 380 views
  • 0 likes
  • 2 in conversation