## How to traspose some variables?

Solved
Occasional Contributor
Posts: 5

# How to traspose some variables?

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

I have this data set:

 ID Gender Disease1 44 2 1390 44 2 1546 44 2 1670 57 1 2980 57 1 1546 83 2 1390

I tried with this:

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

var disease;

by id;

run;

but I want to something like this:

 ID Gender Disease1_1 Disease1_2 Disease1_3 44 2 1390 1546 1670 57 1 2980 1546 - 83 2 1390 - -

How can I do it?

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

## Re: How to traspose some variables?

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

All Replies
Super User
Posts: 23,253

## Re: How to traspose some variables?

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: 8,146

## Re: How to traspose some variables?

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.