BookmarkSubscribeRSS Feed
madan68
Calcite | Level 5

I'd like to create a variable called "Length of stay" by subtracting the separation date (sepdate) from the admit date (addate) in the hosp file.

 

addate= 2008-10--25

sepdate=2008-11-18

 

 I wrote :

data hosp; 

set hosp;

los= sepdate - addate;

run;

 

but it does not work.

thank you

3 REPLIES 3
andreas_lds
Jade | Level 19

Subtracting  strings is not possible. You have to convert the strings to sas dates using input function. You should check why those "dates" have not been converted to sas dates during data import.

 

data coolDates;
   set have(rename=(appDate=strAppDate sepDate=strSepDate));

   length appDate sepDate 8;
   format appDate sepDate yymmdds10.;

   appDate = input(strAppDate, yymmdd10.);
   sepDate = input(strSepDate, yymmdd10.);

   /* Calculations ...*/

   drop strAppDate strSepDate;
run;
Satish_Parida
Lapis Lazuli | Level 10
Make sure sepdate and addate are both Numeric Data Type to have numeric operations.
If not Numeric then convert them to Numeric using informat.
Everything else looks ok.
Kurt_Bremser
Super User

"does not work" is a VERY POOR description of your problem. Supply the log, and give a clear description how the result you got does not meet your expectations. Don't force us to pry important information out of your nose.

sas-innovate-2024.png

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.

 

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