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

Hi there!
Stuck on a problem-- I need to determine the length of stay (in days) between two dates (formatted (mmddyyyy) in my dataset: ex. 01/22/2015). Here's my code:

 
data dates_again;
set work.import;
admitdate=input(mmddyyyy10.);
releasedate=input(mmddyyyy10.);
LOS=intck('dd', releasedate, admitdate);
put los;
run;

 

I get an error message for admitdate and releasedate, "Expecting an arithmetic expression":

64 admitdate=input(mmddyyyy10.);
___________
386
76
65 releasedate=input(mmddyyyy10.);
___________
386
76
ERROR 386-185: Expecting an arithmetic expression.
 

  Help! Not sure what else to do.

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Miracle
Barite | Level 11

Hi please try this

data dates_again;
    set work.import;
    sas_admitdate=input(admitdate,mmddyy10.);
    sas_releasedate=input(releasedate,mmddyy10.);
    LOS=intck('day', sas_releasedate, sas_admitdate);
    put los;
run;

View solution in original post

4 REPLIES 4
ballardw
Super User

 

admitdate=input(mmddyy10.); [ the format only has 2 ys] to actually input would require either a character variable name

admitdate=input(datechar, mmddyy10.); or a date literal string

admitdate=input('02/15/2018', mmddyy10.);

Since "input" didn't work then SAS is expecting an "arithemetic expression";

 

Are your variables admitdate and releasedate character or numeric. Please run proc contents on the set an determine which.

It may be that your variable is numeric with an existing SAS format of mmddyy10 and no conversion is needed or desired.

If the variables are indeed character then you would need to use input but the target variable name must be a different variable:

admitdatenum = input(admitdate, mmddyy10.) and similar for the releasedate.

 

LOS= releasedatenum - admitdatenum +1; 

or

LOS=intck('day',  admitdatenum, releasedatenum) +1;

the +1 is to include both ends. If released on the date of admission otherwise you get 0.

Using intck you would get a negative value with the admitdate after releasedate. DD is not a valid interval for intck.

alyxm
Fluorite | Level 6
Thanks for responding! Actually, my variables for admitdate and releasedate are numeric, so I actually did not have to convert to SAS format of mmddyy10. Thanks again!
Miracle
Barite | Level 11

Hi please try this

data dates_again;
    set work.import;
    sas_admitdate=input(admitdate,mmddyy10.);
    sas_releasedate=input(releasedate,mmddyy10.);
    LOS=intck('day', sas_releasedate, sas_admitdate);
    put los;
run;
alyxm
Fluorite | Level 6

This worked! Thanks so much! I also had to add "+1" at the end of the LOS row to include both the actual admission date and the release date.
Thanks again!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 1978 views
  • 5 likes
  • 3 in conversation