<?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: Extracting Year and Month from Date field issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-and-Month-from-Date-field-issue/m-p/629653#M186257</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21164"&gt;@greg6363&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm trying to create a new field in PROC SQL that uses just the year and month (YYYYMM - ex. 201812) from a date field with the format YYYYMMDD (ex. 20181204) but when I attempt to apply the format, I keep getting the following error message:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: There was a problem with the format so BEST. was used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output shows as scientific notation (2.04E27)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is how I wrote the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table_master as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select revised_date as revised_month format&amp;nbsp;yymm6.&lt;/P&gt;
&lt;P&gt;from primary_table;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The purpose is for the new field will be to group totals by month.&amp;nbsp; What am I doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any feedback is greatly appreciated.&amp;nbsp; Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One suspects that your base variable, revised_date is actually numeric of value 20181204 and not a SAS date value corresponding to the same date that actually accepts date formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the current format assigned to the variable REVISED_DATE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to consider this code:&lt;/P&gt;
&lt;PRE&gt;data junk;
   x=20181204;
   put 'Formatted numeric 20181204: ' x= yymmn6.;
   y = '04DEC2018'd;
   put 'Numeric value of 04DEC2018 SAS Date value: ' y= best8.;

run;&lt;/PRE&gt;
&lt;P&gt;The formatted value for X is displayed with ****** because 20181204 would represent a "date" if basically a numeric value WAY in the future. The date of 01JAN20000, yes year 20,000 has a numeric value of 6588971 and is way smaller than 20181204. The SAS date formats will only display years of 4 digits and the various date functions will give up past year 20000.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you may need to create an actual SAS date value with something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;(put(revised_date, &lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;best8.&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; -L),&lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;yymmdd8.&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;) as revised_month&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Mar 2020 23:24:55 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-03-04T23:24:55Z</dc:date>
    <item>
      <title>Extracting Year and Month from Date field issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-and-Month-from-Date-field-issue/m-p/629643#M186248</link>
      <description>&lt;P&gt;I'm trying to create a new field in PROC SQL that uses just the year and month (YYYYMM - ex. 201812) from a date field with the format YYYYMMDD (ex. 20181204) but when I attempt to apply the format, I keep getting the following error message:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: There was a problem with the format so BEST. was used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output shows as scientific notation (2.04E27)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is how I wrote the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table_master as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select revised_date as revised_month format&amp;nbsp;yymm6.&lt;/P&gt;
&lt;P&gt;from primary_table;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The purpose is for the new field will be to group totals by month.&amp;nbsp; What am I doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any feedback is greatly appreciated.&amp;nbsp; Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 23:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-and-Month-from-Date-field-issue/m-p/629643#M186248</guid>
      <dc:creator>greg6363</dc:creator>
      <dc:date>2020-03-04T23:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Year and Month from Date field issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-and-Month-from-Date-field-issue/m-p/629644#M186249</link>
      <description>&lt;P&gt;&lt;SPAN&gt;select &lt;STRONG&gt;&lt;STRIKE&gt;as&lt;/STRIKE&gt;&lt;/STRONG&gt; revised_date as revised_month format &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;=&lt;/STRONG&gt;&lt;/FONT&gt; yymm&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;n&lt;/FONT&gt;&lt;/STRONG&gt;6.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What about that?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Delete 'as'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;add equal sign (may not be required)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Change format to yymmn6 so that it matches your explanation.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21164"&gt;@greg6363&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm trying to create a new field in PROC SQL that uses just the year and month (YYYYMM - ex. 201812) from a date field with the format YYYYMMDD (ex. 20181204) but when I attempt to apply the format, I keep getting the following error message:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: There was a problem with the format so BEST. was used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output shows as scientific notation (2.04E27)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is how I wrote the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table_master as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select as revised_date as revised_month format&amp;nbsp;yymm6.&lt;/P&gt;
&lt;P&gt;from primary_table;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The purpose is for the new field will be to group totals by month.&amp;nbsp; What am I doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any feedback is greatly appreciated.&amp;nbsp; Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 22:55:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-and-Month-from-Date-field-issue/m-p/629644#M186249</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-04T22:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Year and Month from Date field issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-and-Month-from-Date-field-issue/m-p/629650#M186254</link>
      <description>&lt;P&gt;I made the corrections you noted but I still receive the same error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: There was a problem with the format so BEST. was used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the output that gets generated for each observation:&amp;nbsp;2.02E7&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;???&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 23:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-and-Month-from-Date-field-issue/m-p/629650#M186254</guid>
      <dc:creator>greg6363</dc:creator>
      <dc:date>2020-03-04T23:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Year and Month from Date field issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-and-Month-from-Date-field-issue/m-p/629653#M186257</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21164"&gt;@greg6363&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm trying to create a new field in PROC SQL that uses just the year and month (YYYYMM - ex. 201812) from a date field with the format YYYYMMDD (ex. 20181204) but when I attempt to apply the format, I keep getting the following error message:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: There was a problem with the format so BEST. was used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output shows as scientific notation (2.04E27)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is how I wrote the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table_master as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select revised_date as revised_month format&amp;nbsp;yymm6.&lt;/P&gt;
&lt;P&gt;from primary_table;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The purpose is for the new field will be to group totals by month.&amp;nbsp; What am I doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any feedback is greatly appreciated.&amp;nbsp; Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One suspects that your base variable, revised_date is actually numeric of value 20181204 and not a SAS date value corresponding to the same date that actually accepts date formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the current format assigned to the variable REVISED_DATE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to consider this code:&lt;/P&gt;
&lt;PRE&gt;data junk;
   x=20181204;
   put 'Formatted numeric 20181204: ' x= yymmn6.;
   y = '04DEC2018'd;
   put 'Numeric value of 04DEC2018 SAS Date value: ' y= best8.;

run;&lt;/PRE&gt;
&lt;P&gt;The formatted value for X is displayed with ****** because 20181204 would represent a "date" if basically a numeric value WAY in the future. The date of 01JAN20000, yes year 20,000 has a numeric value of 6588971 and is way smaller than 20181204. The SAS date formats will only display years of 4 digits and the various date functions will give up past year 20000.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you may need to create an actual SAS date value with something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;(put(revised_date, &lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;best8.&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; -L),&lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;yymmdd8.&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;) as revised_month&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 23:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-and-Month-from-Date-field-issue/m-p/629653#M186257</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-04T23:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Year and Month from Date field issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-and-Month-from-Date-field-issue/m-p/629677#M186268</link>
      <description>If you have a date time variable, which has a time component, you need to first use DATEPART() to get just the date part and then apply the format.</description>
      <pubDate>Thu, 05 Mar 2020 02:17:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-and-Month-from-Date-field-issue/m-p/629677#M186268</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-05T02:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Year and Month from Date field issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-and-Month-from-Date-field-issue/m-p/629728#M186299</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21164"&gt;@greg6363&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the output that gets generated for each observation:&amp;nbsp;2.02E7&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;That is not a SAS date value, but a number in the range 202xxxxx. Go back to the step that brought the data into SAS and make sure that this particular column is correctly imported.&lt;/P&gt;
&lt;P&gt;If your data source contains dates without delimiters ("20200305"), proc import will mis-guess this for a simple number.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 08:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-Year-and-Month-from-Date-field-issue/m-p/629728#M186299</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-05T08:00:11Z</dc:date>
    </item>
  </channel>
</rss>

