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-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
  • 4 replies
  • 998 views
  • 1 like
  • 3 in conversation