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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.