Hello,
I just start learning SAS and I need to create a temporary dataset (walkbike6) selecting individuals from the variable paq635 =1 (people that report walking/biking) but do not bring the missing of this variable neither the missing or "do not know (99, 7777, 9999, etc) from the other variables in the dataset. This is my code and it seems to work but I was ask to use WHERE and IF statement and I cannot figure it out how to do it.
I would really appreciate some help.
Lisbeth
DATA WALKBIKE6;
SET NHANES.PAQ_FF;
where paq635 =1 AND paq635 not= .;
IF PAQ605 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAQ620 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAQ650 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAQ665 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAQ635 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAQ610 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAQ625 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAQ655 IN('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAQ670 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAQ640 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAD615 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAD630 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAD660 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAD675 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
IF PAD645 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') THEN DELETE;
RUN;
I suggest looking at the valid range of values for some of your variables. Is it possible that the variables where '77' or '99' are not wanted have '2' or '7' as valid answers? And similar for the varaibles using '7777' or '9999' as don't know, could they have 2, 7, 77 or 99 as valid responses. You may want different values in the IN clause for some of the varaibles.
You need to link those clauses together with OR's, and wrap them all with a preceeding NOT:
...
WHERE NOT(PAQ605 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') OR
PAQ620 IN ('2' '7' '9' '77' '99' '7777' '9999' '.') OR
etc...);
I suggest looking at the valid range of values for some of your variables. Is it possible that the variables where '77' or '99' are not wanted have '2' or '7' as valid answers? And similar for the varaibles using '7777' or '9999' as don't know, could they have 2, 7, 77 or 99 as valid responses. You may want different values in the IN clause for some of the varaibles.
Here are some questions as a starting point.
Are PAQ605, PAQ620, etc. actually character variables or are they numeric? If they are character, the usual way to refer to a missing value would
be ' ' (not '.') but if they are numeric it would be advisable to change the data values permanently before doing any other processing.
If PAQ605 is 9999, do you want to eliminate the entire observation even if there are valid values for other variables?
When you select PAQ635=1, you don't have to check for missing values as well. If the value is 1, it can't be missing.
Start with that much, and your answers will dictate the next steps.
Good luck.
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!
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.