Hello,
I have a dataset with two date variables (call them date 1 and date 2). I'd like to create a third variable that gives me the number of days between the two dates. Date 1 is formatted as MMDDYY10. Date 2 is not formatted and appears as the number of days since Jan 1 1960 (i.e. a 5 digit number in all cases). I tried creating a new variable (call it datedifference) in the data step (datedifference = date 1 - date 2). This returned a variable (datedifference) with all missing values (date 1 and date 2 have no missing values). Next I tried to first format Date 2 to MMDDYY10 and then repeated the prior step. This gave me the same result.
Any suggestions would be much appreciated.
Thanks, Matt
What is the data type of Date1, character or numeric? I suspect it is a character in which case you will need to convert it to a numeric date first.
input(date1,MMDDYY10.) - date2
Other than that, we would need more info.
What is the data type of Date1, character or numeric? I suspect it is a character in which case you will need to convert it to a numeric date first.
input(date1,MMDDYY10.) - date2
Other than that, we would need more info.
Hello, they are both numeric. Thanks.
Hello, @mt88
Formatting is irrelevant to this problem. You state they are both numeric, but if they were both numeric, you would not be getting missing values. So one or both must be character (not numeric). You need to identify the problem by figuring out which one (or both) is character. There should also be warnings or errors in the log. If you show us the ENTIRE log for your data step (including code, NOTEs, WARNINGs and ERRORs) by copying the log as text and pasting it into the window that appears when you click on the </> icon (DO NOT SKIP THIS STEP), we probably can help further.
Thanks all. I managed to figure it out.
Please share the solution with the rest of the SAS Community!
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.