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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 217 views
  • 0 likes
  • 2 in conversation