01-20-2017 01:24 PM
Convert to dates so the SAS date functions work. But first, how do you get a difference of one when both values are 01-15-2017?
Also, do you want the difference in Days, weeks, months, years or something else?
01-20-2017 01:28 PM
Thank you for the response. Actually i have two dates vch are the same and i need to output '1' if the dates r same so i used (end_date-start_date)+1 but its giving a missing value.
01-20-2017 01:40 PM
After looking at the links suggested by @DarthPathos calculate the interval. Then do a test if you need to modify the difference such as:
If difference=0 then difference = 1;
I'm sure I could write a very convoluted one line calculation but it would look ugly or confusing, not be obvious and boil down to the added "if" statement in the end.
If your variables are character then the - should have generated some notes similar to:
NOTE: Invalid numeric data, end_date='01-01-2017' , at line 237 column 11. NOTE: Invalid numeric data, start_date='01-01-2017' , at line 237 column 20. end_date=01-01-2017 start_date=01-01-2017 diff=. _ERROR_=1 _N_=1 NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 237:19
Which tells you that you cannot subtract character values (at least those that can not be easily converted to numeric which 01012017 could) and that "missing value" - "missing value" + 1 = "missing value".
01-20-2017 03:16 PM
The initial calculation would be:
difference = input(end_date, mmddyy10.) - input(start_date, mmddyy10.);
Whether you want to add either of these is up to you:
difference = difference + 1;
if difference = 0 then difference=1;
There are some "study day" calculations in clinical data that don't allow study day 0.
01-20-2017 01:28 PM
I recommend the paper here- specifically the INPUT and INTCK functions. As @ballardw indicated, not sure how you get 1 from the dates given, but the INPUT will convert it to the proper format and INTCK will calculate the difference.