SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
emaneman
Pyrite | Level 9

hello. 

I am using PROC TRANSPOSE to transpose three variables in a dataset, using ID as the BY variable. Data and syntax is included. However, I would like to keep two other variables: age and gender, so that my final file looks like the table below.  I know how to do it with a different method, but at times it would be much more efficient if I could use PROC TRANSPOSE. Any suggestion?

 

id_NAME_COL1genderage
1v13M20
1v24M20
1v33M20
2v14F22
2v23F22
2v32F22
3v15M34
3v21M34
3v35M34

 

 

data have;
input id age gender$ v1 v2 v3;
cards;
1 20 M 3 4 3 
2 22 F 4 3 2
3 34 M 5 1 5
;
proc print;

proc transpose data=have out=want;
var v1 v2 v3;
by id;

proc print;
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @emaneman,

 

Just add the two variables to your BY statement:

by id gender age;

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hello @emaneman,

 

Just add the two variables to your BY statement:

by id gender age;
emaneman
Pyrite | Level 9

how silly of me.

e

himself
Pyrite | Level 9

Hi can have the following:

data have;
input id age gender$ v1 v2 v3;
cards;
1 20 M 3 4 3 
2 22 F 4 3 2
3 34 M 5 1 5
;
proc print;

proc transpose data=have out=want;
var v1 v2 v3;
by id gender age;

proc print;

 

Read more about Proc transpose here:

Taming Proc Transpose  

emaneman
Pyrite | Level 9

thank you.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1867 views
  • 1 like
  • 3 in conversation