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

Hey there,

 

I have a table look like this:

have: 
IDcat
id 1Y1
id 2Y2
id nY m

 

each id is falling into the corresponding category Y. Do we have any solution to transpose the table such that I can have following:

 

want:    
IDY1Y2Ym
id 1100
id 2010
    
id n001

 

In the want table, each id is flagged as 1 only if the corresponding column 'Y' can be found from table want.

 

 

Thanks in advance!!! 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Not sure if I am over simplifying things here?

 

data have;
input ID $ cat $;
infile datalines dlm=',';
var=1;
datalines;
id 1, Y1
id 2, Y2
id 3, Y3
;

proc transpose data=have out=temp(drop=_NAME_);
    by ID ;
    id cat;
    var var;
run;

proc stdize data=temp out=want reponly missing=0;
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Not sure if I am over simplifying things here?

 

data have;
input ID $ cat $;
infile datalines dlm=',';
var=1;
datalines;
id 1, Y1
id 2, Y2
id 3, Y3
;

proc transpose data=have out=temp(drop=_NAME_);
    by ID ;
    id cat;
    var var;
run;

proc stdize data=temp out=want reponly missing=0;
run;
Reeza
Super User
You can drop the VAR statement, SAS defaults it to 1 then 🙂
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
  • 1061 views
  • 3 likes
  • 3 in conversation