I have the following data. A table of events that can contain any number of codes.
data have;
input id$ code$ @@;
datalines;
aa x1 aa x1 aa x2
bb x1 bb y1 bb y1 bb z2 bb z4
cc x1 cc x2 cc y1 cc x1 cc x1 cc q1
dd z2 dd z2 dd z2 dd q1
;
run;
I want to transpose the data so the codes associated with each event is stored in the same row.
image.png
I got it to work by moving the prefix up.
proc transpose data=have out=want (drop=name) prefix=code;
by id;
var code;
run;Thanks.
This seems to work for your example:
proc transpose data=have out=want(drop=name) prefix=code; by id; var code; run;
@cobba wrote:
I have the following data. A table of events that can contain any number of codes.
data have; input id$ code$ @@; datalines; aa x1 aa x1 aa x2 bb x1 bb y1 bb y1 bb z2 bb z4 cc x1 cc x2 cc y1 cc x1 cc x1 cc q1 dd z2 dd z2 dd z2 dd q1 ; run;
I want to transpose the data so the codes associated with each event is stored in the same row.
image.png
I got it to work by moving the prefix up.
proc transpose data=have out=want (drop=name) prefix=code;
by id;
var code;
run;Thanks.
CFC_SAS_Communities_400x225.jpg
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.