SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

How to traspose some variables?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

How to traspose some variables?

Hi
Maybe my problem is very simple, but I can't with this!

I have this data set: 

 

IDGenderDisease1
4421390
4421546
4421670
5712980
5711546
8321390

 

I tried with this: 

 

proc traspose data=example out =example1 prefix=disease;

                       var disease;

                       by id;

run; 

 

 

but I want to something like this: 

 

IDGenderDisease1_1Disease1_2Disease1_3
442139015461670
57129801546-
8321390--

 

How can I do it?


Accepted Solutions
Solution
‎05-29-2017 04:02 AM
PROC Star
Posts: 7,489

Re: How to traspose some variables?

Posted in reply to CarolBarahona

You were close, but your variable is called disease1 .. NOT disease. The following should work:

 

proc transpose data=example 
               out =example1 (drop=_:) 
               prefix=disease1_;
  var disease1;
  by id gender;
run; 

Art, CEO, AnalystFinder.com

View solution in original post


All Replies
Super User
Posts: 19,855

Re: How to traspose some variables?

Posted in reply to CarolBarahona

Putting your data in a wide format will make it more difficult to work with in the long run.

It's common, but it's not because it's a good programming method but because it's common....

 

1. Add an counter variable (1,2,3) so SAS knows the prefix needed and to make each row unique, see link if you need help with this.

2. Then do PROC TRANSPOSE and add the variable to your ID list. 

 

proc transpose data=have out=want prefix=disease_;

by id gender; *you may need to sort as well;

var disease;

id counter;

run;

 

Solution
‎05-29-2017 04:02 AM
PROC Star
Posts: 7,489

Re: How to traspose some variables?

Posted in reply to CarolBarahona

You were close, but your variable is called disease1 .. NOT disease. The following should work:

 

proc transpose data=example 
               out =example1 (drop=_:) 
               prefix=disease1_;
  var disease1;
  by id gender;
run; 

Art, CEO, AnalystFinder.com

Occasional Contributor
Posts: 5

Re: How to traspose some variables?

Thank you very much!
You right, I was close... but I needed a push!

 

 

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 315 views
  • 0 likes
  • 3 in conversation