BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mt88
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
CurtisMackWSIPP
Lapis Lazuli | Level 10

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.

View solution in original post

5 REPLIES 5
CurtisMackWSIPP
Lapis Lazuli | Level 10

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.

mt88
Calcite | Level 5

Hello, they are both numeric. Thanks.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
mt88
Calcite | Level 5

Thanks all. I managed to figure it out.

PaigeMiller
Diamond | Level 26

Please share the solution with the rest of the SAS Community!

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 919 views
  • 1 like
  • 3 in conversation