<?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 Problem with data dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813248#M320917</link>
    <description>&lt;P&gt;Dear SAS users and experts,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to resolve the issue below for my datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the right format for the data Issue_date and Offer_datec but&lt;/P&gt;
&lt;P&gt;I have tried to calculate the diffeence with meaningless results . Please see my file attached&lt;/P&gt;
&lt;P&gt;The code&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data el.Data_test(keep=Issue_date Offer_date Offer_datec Dif_Issue_Offer);
    set Data_ipo4;
     * Dif_Issue_Offer=Listing_datec-Issue_date;
	   * Offer_datec=input(Offer_date,8.);
        *Offer_datec=Offer_datec-0;
        * format Offer_datec YYMMDDN8.;
	     Dif_Issue_Offer=Offer_datec-Issue_Date;
run;&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;Many thanks in advance,&lt;/P&gt;
&lt;P&gt;George&lt;/P&gt;</description>
    <pubDate>Fri, 13 May 2022 15:54:17 GMT</pubDate>
    <dc:creator>georgel</dc:creator>
    <dc:date>2022-05-13T15:54:17Z</dc:date>
    <item>
      <title>Problem with data dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813248#M320917</link>
      <description>&lt;P&gt;Dear SAS users and experts,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to resolve the issue below for my datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the right format for the data Issue_date and Offer_datec but&lt;/P&gt;
&lt;P&gt;I have tried to calculate the diffeence with meaningless results . Please see my file attached&lt;/P&gt;
&lt;P&gt;The code&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data el.Data_test(keep=Issue_date Offer_date Offer_datec Dif_Issue_Offer);
    set Data_ipo4;
     * Dif_Issue_Offer=Listing_datec-Issue_date;
	   * Offer_datec=input(Offer_date,8.);
        *Offer_datec=Offer_datec-0;
        * format Offer_datec YYMMDDN8.;
	     Dif_Issue_Offer=Offer_datec-Issue_Date;
run;&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;Many thanks in advance,&lt;/P&gt;
&lt;P&gt;George&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 15:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813248#M320917</guid>
      <dc:creator>georgel</dc:creator>
      <dc:date>2022-05-13T15:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with data dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813252#M320919</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/360730"&gt;@georgel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear SAS users and experts,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to resolve the issue below for my datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the right format for the data Issue_date and Offer_datec but&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Format is not the issue. Both unformatted variables must be number of days since 01JAN1960 in order for SAS to be able to treat them as dates. Your variable offer_datec is not on this scale. Thus any subtraction will yield gibberish.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set el.Data_test;
    offer_daten=input(put(offer_datec,8.),yymmdd8.);
    Dif_Issue_Offer=Offer_daten-Issue_Date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now Offer_dateN and Issue_Date are on the same scale, number of days since 01JAN1960, and the subtraction works.&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 16:07:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813252#M320919</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-13T16:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with data dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813254#M320920</link>
      <description>&lt;P&gt;offer_datec is a datetime, not date.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use datepart() to convert it to a date variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/360730"&gt;@georgel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear SAS users and experts,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to resolve the issue below for my datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the right format for the data Issue_date and Offer_datec but&lt;/P&gt;
&lt;P&gt;I have tried to calculate the diffeence with meaningless results . Please see my file attached&lt;/P&gt;
&lt;P&gt;The code&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data el.Data_test(keep=Issue_date Offer_date Offer_datec Dif_Issue_Offer);
    set Data_ipo4;
     * Dif_Issue_Offer=Listing_datec-Issue_date;
	   * Offer_datec=input(Offer_date,8.);
        *Offer_datec=Offer_datec-0;
        * format Offer_datec YYMMDDN8.;
	     Dif_Issue_Offer=Offer_datec-Issue_Date;
run;&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;Many thanks in advance,&lt;/P&gt;
&lt;P&gt;George&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 16:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813254#M320920</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-05-13T16:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with data dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813255#M320921</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/360730"&gt;@georgel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear SAS users and experts,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to resolve the issue below for my datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the right format for the data Issue_date and Offer_datec but&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;NO. You have the WRONG format attached to one of those variables.&lt;/P&gt;
&lt;P&gt;This is easy to see by looking at the actual VALUES that they contain.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data="c:\downloads\data_test" min max mean;
  format _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1652458166449.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71434iF1754551024F4C51/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1652458166449.png" alt="Tom_0-1652458166449.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Check those min/max values and see what date or datetime they represent.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input date @@;
  put date=comma12. date :datetime19.  date date9. ;
cards;
 15000.00       20402.00
19880607.00    20200603.00
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;date=15,000 01JAN1960:04:10:00 25JAN2001
date=20,402 01JAN1960:05:40:02 10NOV2015
date=19,880,607 18AUG1960:02:23:27 *********
date=20,200,603 21AUG1960:19:16:43 *********
&lt;/PRE&gt;
&lt;P&gt;It looks like ISSUE_DATE has date values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But OFFER_DATEC has neither DATE nor DATETIME values.&amp;nbsp; It looks like it just has integers in the style YY,YYM,MDD.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you need to convert the values stored in OFFER_DATEC into actual DATE values before you can use it as a date. Either in your calculations or to use with a display format that expects date values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data el.Data_test ;
   set Data_ipo4(keep=ISSUE_DATE OFFER_DATEC);
   offer_datec = input(put(offer_datec,z8.),yymmdd8.);
   Dif_Issue_Offer=Offer_datec-Issue_Date;
   format issue_date offer_datec date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 16:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813255#M320921</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-13T16:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with data dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813256#M320922</link>
      <description>Dear Miller, &lt;BR /&gt;Thanks a million for your quick respond. &lt;BR /&gt;It works perfectly</description>
      <pubDate>Fri, 13 May 2022 16:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813256#M320922</guid>
      <dc:creator>georgel</dc:creator>
      <dc:date>2022-05-13T16:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with data dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813257#M320923</link>
      <description>&lt;P&gt;Those values are not datetime values either.&amp;nbsp; If they are they all from the year 1960.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;offer_datec is a datetime, not date.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use datepart() to convert it to a date variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/360730"&gt;@georgel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear SAS users and experts,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to resolve the issue below for my datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the right format for the data Issue_date and Offer_datec but&lt;/P&gt;
&lt;P&gt;I have tried to calculate the diffeence with meaningless results . Please see my file attached&lt;/P&gt;
&lt;P&gt;The code&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data el.Data_test(keep=Issue_date Offer_date Offer_datec Dif_Issue_Offer);
    set Data_ipo4;
     * Dif_Issue_Offer=Listing_datec-Issue_date;
	   * Offer_datec=input(Offer_date,8.);
        *Offer_datec=Offer_datec-0;
        * format Offer_datec YYMMDDN8.;
	     Dif_Issue_Offer=Offer_datec-Issue_Date;
run;&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;Many thanks in advance,&lt;/P&gt;
&lt;P&gt;George&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 16:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813257#M320923</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-13T16:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with data dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813259#M320924</link>
      <description>&lt;P&gt;Printing some observations from that data set shows this in the log:&lt;/P&gt;
&lt;PRE&gt;220  proc print data=tmp1.data_test (obs=5);
221  run;

NOTE: There were 5 observations read from the data set TMP1.DATA_TEST.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


ERROR: There was a problem with the format so BEST. was used.
ERROR: There was a problem with the format so BEST. was used.
ERROR: There was a problem with the format so BEST. was used.
ERROR: There was a problem with the format so BEST. was used.
ERROR: There was a problem with the format so BEST. was used.
ERROR: There was a problem with the format so BEST. was used.
ERROR: There was a problem with the format so BEST. was used.
ERROR: There was a problem with the format so BEST. was used.
ERROR: There was a problem with the format so BEST. was used.
ERROR: There was a problem with the format so BEST. was used.
ERROR: There was a problem with the format so BEST. was used.
ERROR: There was a problem with the format so BEST. was used.
&lt;/PRE&gt;
&lt;P&gt;The latest date that SAS will use is 31DEC20000 (yes roughly 18,000 years from now) which has a numeric value (number of days) of 6,589,335. Which is considerably smaller than the values of your Order_datec such as 20,141,002.&lt;/P&gt;
&lt;P&gt;If 20141002 is supposed to be 02OCT2014 then you need to convert to an actual date. Something like this:&lt;/P&gt;
&lt;PRE&gt;data example;
  x=20121005;
  datefromx = input(put(x,8. -L),yymmdd10.);
  format datefromx date9.;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 May 2022 16:34:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-data-dates/m-p/813259#M320924</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-05-13T16:34:16Z</dc:date>
    </item>
  </channel>
</rss>

