Hello,
This is my original table:
col |
a; b; c |
b; b; d |
d |
And I want to convert it to:
col | is_a | is_b | is_c | is_d |
a; b; c | 1 | 1 | 1 | 0 |
b; b; d | 0 | 1 | 0 | 1 |
d | 0 | 0 | 0 | 1 |
Any help would be much appreciated!
Jedrek
The straitforward way:
data have;
input col &:$20.;
datalines4;
a; b; c
b; b; d
d
;;;;
data list;
set have;
obs = _n_;
value = 1;
do i = 1 to countw(col,";");
w = strip(scan(col, i, ";"));
output;
end;
drop i;
run;
proc sort data=list nodupkey; by obs w; run;
proc transpose data=list out=table(drop=_name_ obs) prefix=is_;
id w;
var value;
by obs col;
run;
proc stdize data=table reponly missing=0 out=want;
var is_:;
run;
The straitforward way:
data have;
input col &:$20.;
datalines4;
a; b; c
b; b; d
d
;;;;
data list;
set have;
obs = _n_;
value = 1;
do i = 1 to countw(col,";");
w = strip(scan(col, i, ";"));
output;
end;
drop i;
run;
proc sort data=list nodupkey; by obs w; run;
proc transpose data=list out=table(drop=_name_ obs) prefix=is_;
id w;
var value;
by obs col;
run;
proc stdize data=table reponly missing=0 out=want;
var is_:;
run;
Thank you very much! Have a good day.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.