Contributor
Posts: 52

# Continuous variable conditional on answers to 1st/2nd questions & missing data to add to the fun.:)

[ Edited ]

Okay, I have created a continuous variable (see bottom of code). I need to create a do loop to identify the missing within the BEHAVIOR defined variable. My professor has mentioned something like "Count Miss" or something like that. I looked it up but couldn't get a good handle on how to use it.

I *do* know that respondents were asked at minimum 2 questions (evrlt50 or behavior1 (as defined by the BEHAVIOR scale question) and evrgt50 or behavior2 (as defined by the BEHAVIOR scale question). If they answered in the affirmative to both then they were asked the remaining 11 behavior questions. If they answered in the negative to either statement (but not both) they were asked some behavior questions, but not all. If they answered in the negative to both evrlt50/evrgt50 then no further behavior questions were asked.

My professor and I worked out an "idea" ...but....I don't know what command to use to "count the missing"...

if behavior1=1 and behavior2=1 then do;

nummiss=countmiss (behavior3, behavior4, etc. thru behavior 13);

if nummiss=0 then do;

BUT, that does not account for a no (0) to behavior1 and a ye(1)s to behavior2 or a yes(1) to behavior1 and a no(0) to behavior2.

``````*Ever steal anything < \$50?;
if R0361000 not in (.R, .D, .V, .I, .N) THEN DO;
EvrLT50=R0361000; EvrLT50miss=0;
if EvrLT50=1 then evrlt50yes=1; else evrlt50yes=0;
if EvrLT50=0 then evrlt50no=1; else evrlt50no=0;
end;
if R0361000 in (.R, .D, .V, .I, .N) THEN DO;
EvrLT50=R0361000; EvrLT50miss=1;
end;

*Ever steal anything GT \$50 including cars?;
if R0361100 not in (.R, .D, .V, .I, .N) THEN DO;
EvrGT50=R0361100; EvrGT50miss=0;
if EvrGT50=1 then evrgt50yes=1; else evrgt50yes=0;
if EvrGT50=0 then evr50gtno=1; else evrgt50no=1;
end;
if R0361100 in (.R, .D, .V, .I, .N) THEN DO;
EvrGT50=R0361100; EvrGT50miss=1;
end;

*Ever (Help) sell illegal drugs?;
if R0361400 not in (.R, .D, .V, .I, .N) THEN DO;
HLPSLLDRUGS=R0361400; HLPDRGSmiss=0;
if hlpslldrugs=1 then hlpsllyes=1; else hlpsllyes=0;
if hlpslldrugs=0 then hlpsllno=1; hlpsllno=0;
end;
if R0361400 in (.R, .D, .V, .I, .N) THEN DO;
HLPSLLDRUGS=R0361400; HLPDRGSmiss=1;
end;

*Ever steal LT \$50 from a store?;
if R0362100 not in (.R, .D, .V, .I, .N) THEN DO;
LT50store=R0362100; LT50storemiss=0;
if LT50store=1 then lt50storeyes=1; else lt50storeyes=0;
if LT50store=0 then lt50storeno=1; else lt50storeno=0;
end;
if R0362100 in (.R, .D, .V, .I, .N) THEN DO;
LT50store=R0362100; LT50storemiss=1;
end;

*Ever steal purse or wallet (LT \$50)?;
if R0362300 not in (.R, .D, .V, .I, .N) THEN DO;
LT50Pickpocket=R0362300; LT50ppmiss=0;
if LT50Pickpocket=1 then lt50ppyes=1; else lt50ppyes=0;
if LT50Pickpocket=0 then lt50ppno=1; else lt50ppno=0;
end;
if R0362300 in (.R, .D, .V, .I, .N) THEN DO;
LT50Pickpocket=R0362300; LT50ppmiss=1;
end;

*Ever enter a locked building to steal (LT\$50);
if R0362400 not in (.R, .D, .V, .I, .N) THEN DO;
LT50Locked=R0362400; LT50lckdmiss=0;
if LT50Locked=1 then lt50lockedyes=1; else lt50lockedyes=0;
if LT50Locked=0 then lt50lockedno=1; else lt50lockedno=0;
end;
if R0362400 in (.R, .D, .V, .I, .N) THEN DO;
LT50locked=R0362400; LT50lckdmiss=1;
end;

*Ever use a weapon to steal (\$LT50);
if R0362500 not in (.R, .D, .V, .I, .N) THEN DO;
LT50Weapon=R0362500; LT50weapmiss=0;
if LT50Weapon=1 then lt50weapyes=1; else lt50weapyes=0;
if LT50Weapon=0 then lt50weapno=1; else lt50weapno=0;
end;
if R0362500 in (.R, .D, .V, .I, .N) THEN DO;
LT50Weapon=R0362500; LT50weapmiss=1;
end;

*Steal GT \$50 from a store?;
if R0362700 not in (.R, .D, .V, .I, .N) THEN DO;
GT50store=R0362700; GT50storemiss=0;
if GT50store=1 then gt50storeyes=1; else gt50storeyes=0;
if GT50store=0 then gt50storeno=1; else gt50storeno=0;
end;
if R0362700 in (.R, .D, .V, .I, .N) THEN DO;
GT50store=R0362700; GT50storemiss=1;
end;

*Ever steal purse or wallet (GT\$50)?;
if R0362800 not in (.R, .D, .V, .I, .N) THEN DO;
GT50pickpocket=R0362800; GT50ppmiss=0;
if GT50pickpocket=1 then gt50ppyes=1; else gt50ppyes=0;
if GT50pickpocket=0 then gt50ppno=1; else gt50ppno=0;
end;
if R0362800 in (.R, .D, .V, .I, .N) THEN DO;
GT50pickpocket=R0362800; GT50ppmiss=1;
end;

*Ever enter a locked building to steal (GT\$50);
if R0362900 not in (.R, .D, .V, .I, .N) THEN DO;
GT50locked=R0362900; GT50lckdmiss=0;
if GT50Locked=1 then gt50lckdyes=1; else gt50lckdyes=0;
if GT50Locked=0 then gt50lckdno=1; else gt50lckdno=0;
end;
if R0362900 not in (.R, .D, .V, .I, .N) THEN DO;
GT50locked=R0362900; GT50lckdmiss=1;
end;

*Ever steal a vehicle for self or sale?;
if R0363000 not in (.R, .D, .V, .I, .N) THEN DO;
Carthief=R0363000; carthiefmiss=0;
if carthief=1 then caryes=1; else caryes=0;
if carthief=0 then carno=1; else carno=0;
end;
if R0363000 in (.R, .D, .V, .I, .N) THEN DO;
Carthief=R0363000; carthiefmiss=1;
end;

*Ever use a weapon to steal (LT\$50)?;
if R0363100 not in (.R, .D, .V, .I, .N) THEN DO;
GT50Weapon=R0363100; GTWeapmiss=0;
if GT50Weapon=1 then gt50weapyes=1; else gt50weapyes=0;
if GT50Weapon=0 then gt50weapno=1; else gt50weapno=0;
end;
if R0363100 in (.R, .D, .V, .I, .N) THEN DO;
GT50Weapon=R0363100; GTWeapmiss=1;
end;

*Ever sell marijuana?;
if R0365100 not in (.R, .D, .V, .I, .N) THEN DO;
Maryjane=R0365100; MJmiss=0;
if Maryjane=1 then mjyes=1; else mjyes=0;
if Maryjane=0 then mjno=1; else mjno=0;
end;
if R0365100 in (.R, .D, .V, .I, .N) THEN DO;
Maryjane=R0365100; MJmiss=1;
end;

*Ever sold hard illegal drugs?;
if R0365200 not in (.R, .D, .V, .I, .N) THEN DO;
end;
if R0365200 in (.R, .D, .V, .I, .N) THEN DO;
end;

*Behavior Scale;
if evrlt50=1 then behavior1=1; else behavior1=0;
if evrgt50=1 then behavior2=1; else behavior2=0;
if hlpslldrugs=1 then behavior3=1; else behavior3=0;
if lt50pickpocket=1 then behavior4=1; else behavior4=0;
if lt50locked=1 then behavior5=1; else behavior5=0;
if lt50weapon=1 then behavior6=1; else behavior6=0;
if gt50store=1 then behavior7=1; else behavior7=0;
if gt50pickpocket=1 then behavior8=1; else behavior8=0;
if gt50locked=1 then behavior9=1; else behavior9=0;
if carthief=1 then behavior10=1; else behavior10=0;
if gt50weapon=1 then behavior11=1; else behavior11=0;
if maryjane=1 then behavior12=1; else behavior12=0;
if reallybaddrugs=1 then behavior13=1; else behavior13=0;

BEHAVIOR=sum (of behavior1 behavior2 behavior3 behavior4 behavior5 behavior6 behavior7 behavior8 behavior9 behavior10 behavior11 behavior12 behavior13);``````

Now, when I run a proc freq for BEHAVIOR it runs, but I need the conditions above worked in.

Thanks in advance for any and all help!

Super User
Posts: 5,740

## Re: Continuous variable conditional on answers to 1st/2nd questions & missing data to add to th

Your logic makes this an impossible situation.  All the BEHAVIOR variables have no missing values.  They must be either 0 or 1.

There is a function NMISS ... probably the function you are thinking of.  But it would only make sense to apply this to variables that might take on missing values.

Contributor
Posts: 52

## Re: Continuous variable conditional on answers to 1st/2nd questions & missing data to add to th

@Astounding Thank you for your reply. I am sorry for the delay in writing back, I had trouble signing in yesterday.

You are correct, the behavior varaibles are defined as either 0 or 1...but that means that the missing variables become 0. I don't want to overload my 0 when certain responses are valid missing, invalid missing, don't know, or refuse to answer. (The code above the continuous behavior variable shows how I account for the missing in the independent variables) Do you have a suggestion as to how I could account for those in my continuous...so that the missing (R, V, I, N, D) don't end up in my 0 categories for my continuous behavior variable?

Thanks for the NMISS info!

Super User
Posts: 5,740

## Re: Continuous variable conditional on answers to 1st/2nd questions & missing data to add to th

It looks like you already have some special missing values in the data.

Did you know that you can assign these directly, such as:

if ... then behavior13=.N;

Does this become a matter of how to use IF/THEN statements to assign values to the BEHAVIOR variables so that they take on three levels:  0, 1, and missing?

Super User
Posts: 11,822

## Re: Continuous variable conditional on answers to 1st/2nd questions & missing data to add to th

``````if R0365200 not in (.R, .D, .V, .I, .N) THEN DO;
end;
``````

Is the second baddrugsyes=0 supposed to be baddrugsno=0? That is the pattern of many of your varaibles.

If your R0365200 varible has no non-special missings (= .) you could simplify the code to

Contributor
Posts: 52

## Re: Continuous variable conditional on answers to 1st/2nd questions & missing data to add to th

@ballardw THANK YOU for catchign that error!

In the end, I may end up changing to what you suggested. I had to use the missing variable breakdown for a report I gave last week...but I like your suggestion and I will implement it where I can!

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