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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.