<?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 converting problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/date-converting-problem/m-p/884031#M349245</link>
    <description>&lt;P&gt;1,972,252,800 is not a valid date value.&amp;nbsp; With an average of 365.25 days per year that would be past the year 5 million.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;734  data  test;
735    date=1972252800 ;
736    year = 1960 + int(date/365.25);
737
738    put date=comma32. year=comma32. ;
739    put date=datetime20.;
740  run;

date=1,972,252,800 year=5,401,693
date=01JUL2022:00:00:00
&lt;/PRE&gt;
&lt;P&gt;Probably your variable is actually a DATETIME value instead of a DATE value.&amp;nbsp; To find a QUARTER from a DATETIME value first convert the number of seconds to number of days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;qtr(datepart(datetime_value))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jul 2023 22:14:17 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-07-07T22:14:17Z</dc:date>
    <item>
      <title>date converting problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-converting-problem/m-p/884022#M349237</link>
      <description />
      <pubDate>Fri, 07 Jul 2023 21:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-converting-problem/m-p/884022#M349237</guid>
      <dc:creator>nnl3256</dc:creator>
      <dc:date>2023-07-07T21:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: date converting problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-converting-problem/m-p/884025#M349240</link>
      <description>&lt;P&gt;Pieces of code work before, but don't work now. The data test from SQL server and imported in csv format; test is subset of csv, containing 2 rows.&lt;/P&gt;&lt;P&gt;mif_data_reporting_dt is numeric in datetime 16 format. Attached test table and error message.&amp;nbsp; Thanks in advance!&lt;/P&gt;&lt;PRE&gt;proc import out=csv&lt;BR /&gt;datafile="F:\Shared\CMIP\Run81_sas_in.txt"&lt;BR /&gt;dbms=csv replace; &lt;BR /&gt;getnames=Yes;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data new_data;
    set test;
	rptqtr=qtr(mif_data_reporting_dt);
	rptyr=year(mif_data_reporting_dt);
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 22:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-converting-problem/m-p/884025#M349240</guid>
      <dc:creator>nnl3256</dc:creator>
      <dc:date>2023-07-07T22:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: date converting problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-converting-problem/m-p/884026#M349241</link>
      <description>&lt;P&gt;I don't understand.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why are you creating dataset CSV in the first step and then reading from dataset TEST in the second step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a CSV file then just write a data step to read it and you will have full control over how the variables are defined.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 22:06:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-converting-problem/m-p/884026#M349241</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-07T22:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: date converting problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-converting-problem/m-p/884031#M349245</link>
      <description>&lt;P&gt;1,972,252,800 is not a valid date value.&amp;nbsp; With an average of 365.25 days per year that would be past the year 5 million.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;734  data  test;
735    date=1972252800 ;
736    year = 1960 + int(date/365.25);
737
738    put date=comma32. year=comma32. ;
739    put date=datetime20.;
740  run;

date=1,972,252,800 year=5,401,693
date=01JUL2022:00:00:00
&lt;/PRE&gt;
&lt;P&gt;Probably your variable is actually a DATETIME value instead of a DATE value.&amp;nbsp; To find a QUARTER from a DATETIME value first convert the number of seconds to number of days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;qtr(datepart(datetime_value))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 22:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-converting-problem/m-p/884031#M349245</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-07T22:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: date converting problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-converting-problem/m-p/884234#M349318</link>
      <description>&lt;P&gt;Thanks! it works if the date variable was treated ad in DATETIME value.&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;qtr(datepart(datetime_value))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2023 17:56:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-converting-problem/m-p/884234#M349318</guid>
      <dc:creator>nnl3256</dc:creator>
      <dc:date>2023-07-10T17:56:23Z</dc:date>
    </item>
  </channel>
</rss>

