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;
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!
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.