BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lalohg
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Reeza
Super User
Can you provide some more records so we understand how this might scale? How many different combinations will you have? Do you know them all ahead of time?

Why do you need to make dummy variables? Most SAS Procs will do that for you these days.
Ksharp
Super User
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;
lalohg
Quartz | Level 8
this code also worked just fine!!

Thanks again
Ksharp
Super User
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;
lalohg
Quartz | Level 8

Hi  Ksharp,

the code worked just fine!!!!
 
Thank you 
 
have a nice day
 
Lalohg 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 862 views
  • 0 likes
  • 4 in conversation