<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calculate the number of days between two dates not in date9. format in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Calculate-the-number-of-days-between-two-dates-not-in-date9/m-p/983785#M43669</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;01/20/2024 -22/12/2025? N. of days between the dates:&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;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).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your date variables are NUMERIC, then you just do a subtraction, the format differences are irrelevant. Are they numeric, according to PROC CONTENTS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I usually format dates in the date9. format, but in this case, I cannot convert because of standards to be compliant with.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;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, &lt;EM&gt;regardless of the format&lt;/EM&gt;. The format changes the &lt;EM&gt;appearance&lt;/EM&gt;, it does not change the value. If they are character, you can certainly create new numeric variables (as described by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;), and then you can do the subtraction, all without affecting the original variables.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Example with numeric variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Feb 2026 13:04:09 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2026-02-20T13:04:09Z</dc:date>
    <item>
      <title>Calculate the number of days between two dates not in date9. format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-the-number-of-days-between-two-dates-not-in-date9/m-p/983779#M43667</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;could you help me to calculate the number of days between two dates in the formats:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;01/20/2024 -22/12/2025? N. of days between the dates:&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;2024-11-13 - 2025-12-02?&amp;nbsp;N. of days between the dates:&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I usually format dates in the date9. format, but in this case, I cannot convert because of standards to be compliant with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Feb 2026 10:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-the-number-of-days-between-two-dates-not-in-date9/m-p/983779#M43667</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2026-02-20T10:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the number of days between two dates not in date9. format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-the-number-of-days-between-two-dates-not-in-date9/m-p/983780#M43668</link>
      <description>If you have dates stored as character, use the INPUT function with a proper informat to convert the strings to real date values.</description>
      <pubDate>Fri, 20 Feb 2026 10:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-the-number-of-days-between-two-dates-not-in-date9/m-p/983780#M43668</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2026-02-20T10:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the number of days between two dates not in date9. format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-the-number-of-days-between-two-dates-not-in-date9/m-p/983785#M43669</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;01/20/2024 -22/12/2025? N. of days between the dates:&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;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).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your date variables are NUMERIC, then you just do a subtraction, the format differences are irrelevant. Are they numeric, according to PROC CONTENTS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I usually format dates in the date9. format, but in this case, I cannot convert because of standards to be compliant with.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;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, &lt;EM&gt;regardless of the format&lt;/EM&gt;. The format changes the &lt;EM&gt;appearance&lt;/EM&gt;, it does not change the value. If they are character, you can certainly create new numeric variables (as described by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;), and then you can do the subtraction, all without affecting the original variables.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Example with numeric variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Feb 2026 13:04:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-the-number-of-days-between-two-dates-not-in-date9/m-p/983785#M43669</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2026-02-20T13:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the number of days between two dates not in date9. format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-the-number-of-days-between-two-dates-not-in-date9/m-p/983794#M43670</link>
      <description>&lt;P&gt;Variables are not "in date9. format".&amp;nbsp; They are either numeric variables with date values (number of days since start of 1960) that have the DATE9. format specification attached to them.&amp;nbsp; Or they are character variables with strings in the style produced by the DATE9. format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS code FORMAT has a specific meaning.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A FORMAT converts values to text.&amp;nbsp; An INFORMAT converts text to values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if your four variables are numeric with date values you can simply subtract them to find the difference in days, no matter what format specification has been attached to them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
  date1 = '20JAN2024'd;
  date2 = '22DEC2025'd ;
  date3 = '13NOV2024'd;
  date4 = '02DEC2025'd ;
  format date1 mmddyy10. date2 ddmmyy10. date3 date4 yymmdd10.;
  diff1 = date2 - date1;
  diff2 = date4 - date3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if they are character then you can first convert them to dates using the INPUT() function and an appropriate informat.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date example2;
  date1='01/20/2024';
  date2='22/12/2025';
  date3 = '2024-11-13';
  date4 = '2025-12-02';
  diff1 = input(date2,ddmmyy10.) - input(date1,mmddyy10.);
  diff2 = input(date4,yymmdd10.) - input(date3,yymmdd10.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NOTE: if you have a single character variables where the style of the strings is different on different observations it will be harder. You might try using the ANYDTDTE informat.&amp;nbsp; But make sure that you do not have ambiguous&amp;nbsp;strings.&amp;nbsp; There is no way to tell whether 10/12/2025 is supposed to mean the tenth of December or October twelfth without some external knowledge about whether the fields are in DMY or MDY order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Feb 2026 14:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-the-number-of-days-between-two-dates-not-in-date9/m-p/983794#M43670</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-02-20T14:57:40Z</dc:date>
    </item>
  </channel>
</rss>

