01/20/2024 -22/12/2025? N. of days between the dates:
So you have one date that appears as MMDDYYYY and the other date appears as DDMMYYYY? Is that right? (A rather poor way to design a data set, in my opinion).
If your date variables are NUMERIC, then you just do a subtraction, the format differences are irrelevant. Are they numeric, according to PROC CONTENTS?
I usually format dates in the date9. format, but in this case, I cannot convert because of standards to be compliant with.
Dates are stored as either numeric or character values, they are not stored as formatted values. A format can be optionally assigned to the value, but if they are numeric, they are stored as the integer number of days since 01JAN1960, and so a simple subtraction would give you answer, regardless of the format. The format changes the appearance, it does not change the value. If they are character, you can certainly create new numeric variables (as described by @Kurt_Bremser ), and then you can do the subtraction, all without affecting the original variables.
Example with numeric variables:
data fake; /* Note: date1 and date2 are numeric */
date1='20JAN2024'd;
date2='22DEC2025'd;
format date1 mmddyy10. date2 ddmmyy10.; /* Note different formats for the two variables */
run;
proc print data=fake;
run;
data compute_difference;
set fake;
difference = date2-date1;
run;
proc print data=compute_difference;
run;
... View more