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:
I get an error message for admitdate and releasedate, "Expecting an arithmetic expression":
Help! Not sure what else to do.
Thank you!
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;
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.
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;
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!
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.