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:    
IDY1Y2…Ym
id 110…0
id 201…0
…    
id n00…1

 

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 🙂

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

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
  • 1911 views
  • 3 likes
  • 3 in conversation