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. 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;
... View more