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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1034 views
  • 1 like
  • 4 in conversation