Quantcast

DO IF and missing values

classic Classic list List threaded Threaded
4 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DO IF and missing values

Ron0z
DO-IF doesn’t seem to like missing values.  Is there a way of specifying missing values that DO-IF will accept?

My data was derived by linking 3 system files (match files) the result of which creates a variable where some records have system missing values, but that’s perfectly logical the way the data is structured. Datasets have been used, though I wouldn’t expect that to make any difference to my issue; I just mention it for completeness. I’ve included only 3 records of my data in the examples for clarity.

1: My initial use of DO-IF came out wrong. There should be no missing values for CAP.

compute IndexFactor = 1.017.

do if (passrate ge 75).
+ compute  cap = n558 * 1.1 * IndexFactor.
else if (passrate ge 50).
+ compute  cap = n558 * 0.75 * IndexFactor.
else if (passrate lt 50).
+ compute  cap = n558 * 0.5 * IndexFactor.
else if missing(passrate).
+ compute  cap = n558 * 0.75 * IndexFactor.
else.
+ compute cap = -9.
end if.

list vars = e307 passrate n558 IndexFactor cap.

e307       passrate     n558 IndexFactor      cap

10052NAT     100.00  2360.00       1.02   2640.13
AHC50410      57.38  1640.00       1.02   1250.91
BSB50215        .    2240.00       1.02       .

 

2: Setting PASSRATE to zero works as shown in my edited DO-IF statement.

if missing(passrate) passrate = 0.

compute IndexFactor = 1.017.

do if (passrate ge 75).
+ compute  cap = n558 * 1.1 * IndexFactor.
else if (passrate ge 50).
+ compute  cap = n558 * 0.75 * IndexFactor.
else if (passrate eq 0).
+ compute  cap = n558 * 0.75 * IndexFactor.
else.
+ compute  cap = -9.
end if.

list vars = e307 passrate n558 IndexFactor cap.

e307       passrate     n558 IndexFactor      cap

10052NAT     100.00  2360.00       1.02   2640.13
AHC50410      57.38  1640.00       1.02   1250.91
BSB50215        .00  2240.00       1.02   1708.56
 
 



Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DO IF and missing values

Jon Peck
You need to put the missing test first as otherwise the other expressions can't be evaluated, so the else clauses won't be evaluated.


On Sun, Jan 8, 2017 at 4:04 PM Ron0z <[hidden email]> wrote:
DO-IF doesn’t seem to like missing values.  Is there a way of specifying

missing values that DO-IF will accept?



My data was derived by linking 3 system files (match files) the result of

which creates a variable where some records have system missing values, but

that’s perfectly logical the way the data is structured. Datasets have been

used, though I wouldn’t expect that to make any difference to my issue; I

just mention it for completeness. I’ve included only 3 records of my data in

the examples for clarity.



1: My initial use of DO-IF came out wrong. There should be no missing values

for CAP.



compute IndexFactor = 1.017.



do if (passrate ge 75).

+ compute  cap = n558 * 1.1 * IndexFactor.

else if (passrate ge 50).

+ compute  cap = n558 * 0.75 * IndexFactor.

else if (passrate lt 50).

+ compute  cap = n558 * 0.5 * IndexFactor.

else if *missing(passrate).*

+ compute  cap = n558 * 0.75 * IndexFactor.

else.

+ compute cap = -9.

end if.



list vars = e307 passrate n558 IndexFactor cap.



e307       passrate     n558 IndexFactor      cap



10052NAT     100.00  2360.00       1.02   2640.13

AHC50410      57.38  1640.00       1.02   1250.91

*BSB50215        .    2240.00       1.02       .*







2: Setting PASSRATE to zero works as shown in my edited DO-IF statement.



*if missing(passrate) passrate = 0.*



compute IndexFactor = 1.017.



do if (passrate ge 75).

+ compute  cap = n558 * 1.1 * IndexFactor.

else if (passrate ge 50).

+ compute  cap = n558 * 0.75 * IndexFactor.

else if *(passrate eq 0).*

+ compute  cap = n558 * 0.75 * IndexFactor.

else.

+ compute  cap = -9.

end if.



list vars = e307 passrate n558 IndexFactor cap.



e307       passrate     n558 IndexFactor      cap



10052NAT     100.00  2360.00       1.02   2640.13

AHC50410      57.38  1640.00       1.02   1250.91

BSB50215        .00  2240.00       1.02   *1708.56*



















--

View this message in context: http://spssx-discussion.1045642.n5.nabble.com/DO-IF-and-missing-values-tp5733655.html

Sent from the SPSSX Discussion mailing list archive at Nabble.com.



=====================

To manage your subscription to SPSSX-L, send a message to

[hidden email] (not to SPSSX-L), with no body text except the

command. To leave the list, send the command

SIGNOFF SPSSX-L

For a list of commands to manage subscriptions, send the command

INFO REFCARD

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DO IF and missing values

Ron0z
Perfect.  Thank you.  So, simple.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DO IF and missing values

Art Kendall
In the long run it is a great aid in quality assurance and debugging to reserve "system missing" for situations where the system cannot follow your instructions.
User missing values can carry all the reasons why a values would be missing.

If you complete the prep of your 3 input system files, they would contain no system missing values.  It would only take a few lines of syntax to clean up the system missing values that are created in the match.
something like
recode myvars (sysmis = -9999999) (else=copy).

If you have preserved the previous syntax so you can go back and change your syntax so it does what you mean rather than what you say, then this is an instance where it would not be shooting yourself in the foot to skip INTO on the recode.
Art Kendall
Social Research Consultants
Loading...