Hello there,
I have a variable with combination of colors
ID variable_combination
1 "blue, yellow, red"
2 "white, grey"
and would like to get new indicator variables for each combination so I will get:
ID variable_combination blue_yellow_red white_grey
1 "blue, yellow, red" 1 0
2 "white, grey" 0 1
all your help will be appreciated
Thanks
Lalohg
It's hard to imagine a use for such a thing. It is not hard to image how this method will fail since SAS variable names can not exceed 32 characters.
Why do you want this? Perhaps we can find better approaches.
It's hard to imagine a use for such a thing. It is not hard to image how this method will fail since SAS variable names can not exceed 32 characters.
Why do you want this? Perhaps we can find better approaches.
data have;
input ID variable_combination $40.;
cards;
1 "blue, yellow, red"
2 "white, grey"
;
data temp;
set have;
length _ $ 40;
do i=1 to countw(variable_combination,,'ka');
_=catx('_',_,scan(variable_combination,i,,'ka'));
end;
y=1;
run;
proc logistic data=temp outdesign=design(drop=y) outdesignonly;
class _ / param=glm ;
model y=_/nofit noint;
run;
data want;
merge have design;
run;
data have;
input ID variable_combination $40.;
v=1;
cards;
1 "blue, yellow, red"
2 "white, grey"
;
proc transpose data=have out=temp;
by id variable_combination;
var v;
id variable_combination;
run;
proc stdize data=temp out=want reponly missing=0;
run;
Hi Ksharp,
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.