Difference between two dates- Length of Stay (days)

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Difference between two dates- Length of Stay (days)

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!


Accepted Solutions
Solution
‎03-01-2018 11:50 PM
Regular Contributor
Posts: 249

Re: Difference between two dates- Length of Stay (days)

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


All Replies
Super User
Posts: 12,654

Re: Difference between two dates- Length of Stay (days)

 

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.

New Contributor
Posts: 3

Re: Difference between two dates- Length of Stay (days)

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!
Solution
‎03-01-2018 11:50 PM
Regular Contributor
Posts: 249

Re: Difference between two dates- Length of Stay (days)

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;
New Contributor
Posts: 3

Re: Difference between two dates- Length of Stay (days)

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!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 149 views
  • 5 likes
  • 3 in conversation