BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
CJK7
Calcite | Level 5

I have a variable (race) that has 15 levels.  The levels are coded 1-13, 888, 999.  This was a check all that apply question, so multiple codes appear in the same cell, seperated by a comma (,).  In the past I have used the find function to create flag variables for each level (see below for code), however because the variable levels include more than one digit this produces inaccurate values.  For example a respondent that selected level 13 is being counted as level 3 as well.

Screenshot 2024-10-03 112249.jpg

 

data two;
    set one;
    if find(race, '1')>0 then race_1=1;
    if find(race, '2')>0 then race_2=1;
    if find(race, '3')>0 then race_3=1;
    if find(race, '4')>0 then race_4=1;
    if find(race, '5')>0 then race_5=1;
    if find(race, '6')>0 then race_6=1;
    if find(race, '7')>0 then race_7=1;
    if find(race, '8')>0 then race_8=1;
    if find(race, '9')>0 then race_9=1;
    if find(race, '10')>0 then race_10=1;
    if find(race, '11')>0 then race_11=1;
    if find(race, '12')>0 then race_12=1;
    if find(race, '13')>0 then race_13=1;
    if find(race, '888')>0 then race_888=1;
    if race=999 or race=' ' then race_999=1;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
1 REPLY 1
Tom
Super User Tom
Super User

Use FINDW() instead.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 1 reply
  • 140 views
  • 0 likes
  • 2 in conversation