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

Hello, I have a question:

 

I am working with the Allbus 2004 (like a census) and Need to eliminate all People, who do not have children in the household. For that, I tried to use the following Code:

 

if v483 in (1 2 5 6 7 8 9 10 11 12 13 14 15 16 99) then v483=.;
if v493 in (1 2 5 6 7 8 9 10 11 12 13 14 15 16 99) then v493=.;
if v503 in (1 2 5 6 7 8 9 10 11 12 13 14 15 16 99) then v503=.;
if v513 in (1 2 5 6 7 8 9 10 11 12 13 14 15 16 99) then V513=.;
if v523 in (1 2 5 6 7 8 9 10 11 12 13 14 15 16 99) then V523=.;
if v533 in (1 2 5 6 7 8 9 10 11 12 13 14 15 16 99) then v533=.;
if v543 in (1 2 5 6 7 8 9 10 11 12 13 14 15 16 99) then v543=.;
run;

In the codebook, the questions for These variable are roughly translated "what is the relation for Household member Number (and then it goes 2, 3, ... for every mentioned variable) to you"

 

Now what I wanted to do is eliminate all the People, who did not answer with 3 or 4 (3=biological and 4=adoptive). I do not know though, how to eliminate a Person that didn't answer 3 or 4 even once in all those variables.

 

I Need to know now if 1. my logic is right in this Code and 2. how I can Kind of chain These together. Can I use "&" between each one?

 

I ask this because I am actually not sure if coding a missing will "eliminate" this Person all together, so that the people who didn't answer V483 with 3 or 4 will not even be there anymore to be coded by the next if-statement.

 

I really hope, that the way I described my Problem made even a Little sense. At this Point I am so confused by my own logic that I wasn't even able to describe it in my native language to my professor. Thank you for your time and help in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

So you want to keep all persons who answered 3 or 4 to at least one of these questions?

 

If yes, a simple subsetting IF will do it:

if
  v483 in (3,4) or
  v493 in (3,4) or
  v503 in (3,4) or
  v513 in (3,4) or
  v523 in (3,4) or
  v533 in (3,4) or
  v543 in (3,4)
;

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

So you want to keep all persons who answered 3 or 4 to at least one of these questions?

 

If yes, a simple subsetting IF will do it:

if
  v483 in (3,4) or
  v493 in (3,4) or
  v503 in (3,4) or
  v513 in (3,4) or
  v523 in (3,4) or
  v533 in (3,4) or
  v543 in (3,4)
;
Ioannas
Calcite | Level 5

Hello, thank you for your answer.

 

So do I mean I basically can copy your Code? Because I thought there has to be some Kind of consequence to the if-statement.

 

To eliminate everybody who hasn't answered with 3 or 4 at least once I can use the following code as it is right?

if
  v483 in (3,4) or
  v493 in (3,4) or
  v503 in (3,4) or
  v513 in (3,4) or
  v523 in (3,4) or
  v533 in (3,4) or
  v543 in (3,4)
then keep;

 

will that eliminate all people who didn't answer with 3 or 4?

 

 

PaigeMiller
Diamond | Level 26
then keep;

will cause an error in SAS

 

The code presented by @Kurt_Bremser, used exactly as he has written it, will cause the desired records to be kept and others deleted. When there is an IF but no THEN, that's what happens.

--
Paige Miller
Ioannas
Calcite | Level 5
thank you so so much! you two helped me more than you know 🙂

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 552 views
  • 0 likes
  • 3 in conversation