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
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)
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)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.