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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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