Help using Base SAS procedures

Help with SAS procedure, data from columns to rows

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Help with SAS procedure, data from columns to rows

An example of my data currently looks like this. A person can have an unspecified number of locations, as 1002 has 6 locations, 1004 has 4 locations, and 1005 has 2 locations. Others not shown here have even more than 6 locations.


id

location

1002

a

1002

b

1002

c

1002

1002

e

1002

f

1004

a

1004

b

1004

c

1004

1005

a

1005

b

How would I convert the data to look this below? I want each person to only have one row and fill in a column for location 1 to location 2 to 3 to 4 to 5 to 6 to 7, etc..

idlocation1location2location3location4location5location6
1002abcdef
1004abcd
1005ab

Thanks!


Accepted Solutions
Solution
‎12-03-2014 05:27 PM
Respected Advisor
Posts: 4,925

Re: Help with SAS procedure, data from columns to rows

Posted in reply to SASbeginner20

Try this:

proc sort data=have; by id location; run;

data have0 / view=have0;

set have; by id;

if first.id then var=0;

var + 1;

run;

proc transpose data=have0 out=want(drop=_name_) prefix=location;

by id;

var location;

id var;

run;

PG

PG

View solution in original post


All Replies
Solution
‎12-03-2014 05:27 PM
Respected Advisor
Posts: 4,925

Re: Help with SAS procedure, data from columns to rows

Posted in reply to SASbeginner20

Try this:

proc sort data=have; by id location; run;

data have0 / view=have0;

set have; by id;

if first.id then var=0;

var + 1;

run;

proc transpose data=have0 out=want(drop=_name_) prefix=location;

by id;

var location;

id var;

run;

PG

PG
🔒 This topic is solved and locked.

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

Discussion stats
  • 1 reply
  • 141 views
  • 0 likes
  • 2 in conversation