Hey there,
I have a table look like this:
have: | |
ID | cat |
id 1 | Y1 |
id 2 | Y2 |
… | … |
id n | Y 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: | ||||
ID | Y1 | Y2 | … | Ym |
id 1 | 1 | 0 | … | 0 |
id 2 | 0 | 1 | … | 0 |
… | ||||
id n | 0 | 0 | … | 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!!!
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;
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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: