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)
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.