<?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: Date reading as 1960 after conversion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-reading-as-1960-after-conversion/m-p/860484#M339922</link>
    <description>&lt;P&gt;If it is a date variable, and you then use the DATEPART function on it, you get incorrect results. So don't use DATEPART on date values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, this is particularly unhelpful:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;eff_date = ............; /*this is&amp;nbsp;how the database reads the eff_date.  it is a date field*/&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why don't you show us the actual value?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Feb 2023 17:07:47 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-02-23T17:07:47Z</dc:date>
    <item>
      <title>Date reading as 1960 after conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-reading-as-1960-after-conversion/m-p/860475#M339916</link>
      <description>&lt;PRE&gt;data test;
eff_date = ............; /*this is&amp;nbsp;how the database reads the eff_date.  it is a date field*/
eff_date1 = datepart(eff_date);
format eff_date1 date9.;
run;
&lt;/PRE&gt;
&lt;P&gt;It produces&amp;nbsp;22AUG1960 for each and every row in the data.&amp;nbsp; Is there a fix&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 15:34:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-reading-as-1960-after-conversion/m-p/860475#M339916</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2023-02-23T15:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: Date reading as 1960 after conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-reading-as-1960-after-conversion/m-p/860484#M339922</link>
      <description>&lt;P&gt;If it is a date variable, and you then use the DATEPART function on it, you get incorrect results. So don't use DATEPART on date values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, this is particularly unhelpful:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;eff_date = ............; /*this is&amp;nbsp;how the database reads the eff_date.  it is a date field*/&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why don't you show us the actual value?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 17:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-reading-as-1960-after-conversion/m-p/860484#M339922</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-23T17:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Date reading as 1960 after conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-reading-as-1960-after-conversion/m-p/860486#M339924</link>
      <description>&lt;P&gt;Show us your input data value, that actual eff_date value and real code.&lt;/P&gt;
&lt;P&gt;The example that you post does not run as two . as you used them are not allowed in an assignment.&lt;/P&gt;
&lt;PRE&gt;6    data test;
7    eff_date = ............; /*this is how the database reads the eff_date.  it is a date field*/
                 -
                 388
                 200
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

8    eff_date1 = datepart(eff_date);
9    format eff_date1 date9.;
10   run;


&lt;/PRE&gt;
&lt;P&gt;Note that other databases date approaches are not the same as SAS and conversion may be needed. The SAS DATEPART function expects a SAS datetime value, which is a number of seconds from 01JAN1960:00:00:00, as input. If the value provided by the database is other than that, and most are, then the SAS date functions may not be appropriate. Also, how you connect to an external database can have an impact on this process. Some connections have the ability to convert on the file and others do not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you seeing that date in SAS or the external database? The date you show corresponds to a numeric 234.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 16:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-reading-as-1960-after-conversion/m-p/860486#M339924</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-23T16:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Date reading as 1960 after conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-reading-as-1960-after-conversion/m-p/860505#M339934</link>
      <description>&lt;P&gt;Date values are the number of days since 1960.&amp;nbsp; So the date value for 22AUG1960 is the number 234.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dateteime values are the number of seconds since 1960.&lt;/P&gt;
&lt;P&gt;The DATEPART() function converts from seconds to days. So basically it just divides by the number of seconds in a day.&lt;/P&gt;
&lt;PRE&gt;3212  data _null_;
3213    date='22AUG1960'd ;
3214    datetime=dhms(date,0,0,0);
3215    put (date datetime)(=comma24.)
3216     /  (date datetime)(=date9.)
3217     /  (date datetime)(=datetime19.)
3218    ;
3219  run;

date=234 datetime=20,217,600
date=22AUG1960 datetime=*********
date=01JAN1960:00:03:54 datetime=22AUG1960:00:00:00
&lt;/PRE&gt;
&lt;P&gt;So you can see that you probably started with a date value close to&amp;nbsp;20,217,600.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I suspect that some has just stored integers into your date variable and used integers that would look to a human like a date created using digits for YYYYMMDD.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So to convert just use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;eff_date1 = input(put(eff_date,z8.),yymmdd8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 17:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-reading-as-1960-after-conversion/m-p/860505#M339934</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-23T17:31:37Z</dc:date>
    </item>
  </channel>
</rss>

