Calcite | Level 5

Using missing values in an if statement

I have this code in SAS and don't know why it is comparing if missing is less than a value.  Is it to exclude the missing values?  What is the if statement doing?

precipday = precipitationdays_from_database_query;

if . lt precipday lt 0 then precipday = 0.1

1 ACCEPTED SOLUTION

Accepted Solutions
Diamond | Level 26

Re: Using missing values in an if statement

``if . lt precipday lt 0 then precipday = 0.1;``

To be very picky, the line of code you provided will do nothing without a semi-colon on the end. So I added one there, I assume you're going to actually have a semi-colon on the end. Please provide us code examples with proper semi-colons from now on.

The syntax , for example

``if 60 < variablename < 80 then do;``

compares the value of variable VARIABLENAME to 60 and 80 — and if 60 is less than this value and this value is less than 80, then the code tells SAS to do something. In your case, it compares the value of PRECIPDAY to missing and to zero and if missing is less than the value, and the value is less than 0, then SAS should do something, specifically set PRECIPDAY = 0.1. In SAS, missing values are considered to be less than any negative number. (Or to phrase it another way, negative number will have PRECIPDAY set to 0.1, but missings will not have PRECIPDAY set to 0.1, and positive numbers will not have PRECIPDAY set to 0.1)

--
Paige Miller
2 REPLIES 2
Diamond | Level 26

Re: Using missing values in an if statement

``if . lt precipday lt 0 then precipday = 0.1;``

To be very picky, the line of code you provided will do nothing without a semi-colon on the end. So I added one there, I assume you're going to actually have a semi-colon on the end. Please provide us code examples with proper semi-colons from now on.

The syntax , for example

``if 60 < variablename < 80 then do;``

compares the value of variable VARIABLENAME to 60 and 80 — and if 60 is less than this value and this value is less than 80, then the code tells SAS to do something. In your case, it compares the value of PRECIPDAY to missing and to zero and if missing is less than the value, and the value is less than 0, then SAS should do something, specifically set PRECIPDAY = 0.1. In SAS, missing values are considered to be less than any negative number. (Or to phrase it another way, negative number will have PRECIPDAY set to 0.1, but missings will not have PRECIPDAY set to 0.1, and positive numbers will not have PRECIPDAY set to 0.1)

--
Paige Miller
Calcite | Level 5

Re: Using missing values in an if statement

Sorry about the semicolon. I hit POST and then realized it. Thank you for
the explanation. I have a multitude of similar if statements and now I
understand what they do.
Again, Thank You!
Discussion stats
• 2 replies
• 782 views
• 0 likes
• 2 in conversation