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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.