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 🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1345 views
  • 0 likes
  • 3 in conversation