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 | d |
1002 | e |
1002 | f |
1004 | a |
1004 | b |
1004 | c |
1004 | d |
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..
id | location1 | location2 | location3 | location4 | location5 | location6 |
1002 | a | b | c | d | e | f |
1004 | a | b | c | d | ||
1005 | a | b |
Thanks!
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
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.