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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.