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"
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;
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.
The data set I have is temporary so I am not sure how I would send it to you.
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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.