BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASbeginner20
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

1 REPLY 1
PGStats
Opal | Level 21

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 1010 views
  • 0 likes
  • 2 in conversation