BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
somedayroy
Calcite | Level 5

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
PaigeMiller
Diamond | Level 26
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

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
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
somedayroy
Calcite | Level 5
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!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 895 views
  • 0 likes
  • 2 in conversation