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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 775 views
  • 0 likes
  • 2 in conversation