To see the actual values for the numeric variables you might want to remove the format from them also.
format _numeric_ ;
For example these two variables must be numeric since they did not get quoted.
ethnicityomb=Not Hispanic or Latino sex_5=Female
The values you have posted for COUNTRYCIT has a single space, but perhaps it has been modified by being pasted into the body of your message. To see the actual values of the bytes in the character variables you can use the $HEX format which will print two hexadecimal digits for each byte. So the value ' 1' would print as 2031 since '20'x is the ASCII code for a space and '31'x is the ASCII code for the character 1.
If they are spaces you could also just try using the LEFT() or STRIP() function to remove the leading spaces in your WHERE and/or IF statement. So either of these statements should find that record.
where countrycit=' 1' ;
where left(countrycit)='1' ;
Take it step by step.
Apply the first criteria.
data step1;
set IAT2016_raw;
where left(countrycit)='1';
run;
Then the next:
data step2;
set step1;
set IAT2016_raw;
where occupation_self in ('29-1000','31-1000');
run;
Then the next:
data step3;
set step2;
where sex_5 in (1,2);
run;
So is 8,364 the sample size you expected?
The issue was the occupation code. You were comparing the formatted value to a list of the coded values because you used the PUT() function in the WHERE statement.
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.