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

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

1 ACCEPTED SOLUTION

Accepted Solutions
cobba
Obsidian | Level 7

 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.

View solution in original post

2 REPLIES 2
ballardw
Super User

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


 

cobba
Obsidian | Level 7

 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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1162 views
  • 1 like
  • 2 in conversation