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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

3 REPLIES 3
LinusH
Tourmaline | Level 20

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...);

Data never sleeps
ballardw
Super User

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.

Astounding
PROC Star

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 940 views
  • 3 likes
  • 4 in conversation