Solved
New Contributor
Posts: 3

# 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;
releasedate=input(mmddyyyy10.);
put los;
run;

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

___________
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)

``````data dates_again;
set work.import;
sas_releasedate=input(releasedate,mmddyy10.);
put los;
run;``````

All Replies
Super User
Posts: 13,563

## 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

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:

or

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)

``````data dates_again;
set work.import;
sas_releasedate=input(releasedate,mmddyy10.);
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.

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