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

Can anyone provide some insight as to why this code is wrong:

 

data analytic4;
set analytic3;

if admitdif1 lt "30" OR admitdif1a lt "30" OR admitdif2 lt "30" OR admitdif2a lt "30" OR admitdif3 lt "30" OR admitdif3a lt "30"
OR admitdif4 lt "30" OR admitdif4a lt "30" OR admitdif5 lt "30" OR admitdif5a lt "30" OR admitdif6 lt "30" OR admitdif6a lt "30" then admit30day="1";

else admit30day="0";
RUN;

 

All the observations are coding as a "1" 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

See the comment above about missing values. It's highly likely this is the issue. 

Use the min function to get smallest non missing value. 

 

If Min(of admitdif1-admitdif6) < 30 then var=1;

else var=0;

View solution in original post

5 REPLIES 5
ballardw
Super User

Provide some of your input data where you do not expect to get 1 for a result.

 

A common issue when using LT or LE comparisons is forgetting that Missing values are always less than any value. So if any of your variables is missing then that LT condition is true and would get the 1 assignment.

 

 

 

malikah_sph
Calcite | Level 5

The data set I have is temporary so I am not sure how I would send it to you. 

Reeza
Super User

See the comment above about missing values. It's highly likely this is the issue. 

Use the min function to get smallest non missing value. 

 

If Min(of admitdif1-admitdif6) < 30 then var=1;

else var=0;

Astounding
PROC Star

Are your variables really character variables? 

 

If so, making character comparisons is tricky.  For example:

 

if "100" < "30" then var=1;

 

This comparison is true.  As a character string, "100" is less than "30" because "1" is less than "3".

 

Still, as has been suggested, the first place to look is for missing values.

malikah_sph
Calcite | Level 5
Thank you so very much! That worked!

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
  • 5 replies
  • 1333 views
  • 1 like
  • 4 in conversation