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,
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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: