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

Hi,

 

I have a data table in the following form:

 

Company Var year_2001 year_2002
A x 11 31
A y 12 32
A z 13 33
B x 21 41
B y 22 42

 

And I would like this table to be transformed into the following table:

 

Company year x y z
A year_2001 11 12 13
A year_2002 31 32 33
B year_2001 21 22 .
B year_2002 41 42 .

 

So here what I need is to transform the values of "Var" into columns, and to transform the "2001" and "2002" columns into a new column "Year".

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
SuzanneDorinski
Lapis Lazuli | Level 10
data want;
  input company $ var $ year_2001 year_2002;
  datalines;
A x 11 31
A y 12 32
A z 13 33
B x 21 41
B y 22 42
;
run;

proc print data=want;
run;

proc transpose data=want 
               out=have
               name=year;
  by company;
  id var;
run;

proc print data=have;
run;

 

EDIT - realized after posting that I probably should have reversed the data set names.  🙂

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

2001 and 2002 are not valid SAS variable names 🙂

SuzanneDorinski
Lapis Lazuli | Level 10
data want;
  input company $ var $ year_2001 year_2002;
  datalines;
A x 11 31
A y 12 32
A z 13 33
B x 21 41
B y 22 42
;
run;

proc print data=want;
run;

proc transpose data=want 
               out=have
               name=year;
  by company;
  id var;
run;

proc print data=have;
run;

 

EDIT - realized after posting that I probably should have reversed the data set names.  🙂

sas-innovate-2024.png

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.

 

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
  • 2 replies
  • 700 views
  • 3 likes
  • 3 in conversation