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?
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.