<?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 date9. date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856441#M338398</link>
    <description>&lt;P&gt;I add that ChatGPT did not give you the best answer, it did not give you the easiest answer, and it gave you an answer that will cause difficulties if you need to perform arithmetic or logical operations on these month values (because these month values are now character, and you can't do math easily on character strings).&lt;/P&gt;</description>
    <pubDate>Tue, 31 Jan 2023 12:19:46 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-01-31T12:19:46Z</dc:date>
    <item>
      <title>Extracting year and month from date9. date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856421#M338388</link>
      <description>&lt;P&gt;Hi, I need help in extracting year and month from date9. date from the following sample data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data work.dates;
	format my_date date9.;
	input my_date date9.;
	datalines;
08JAN2019
26JUN2020
05DEC2021
;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data Want&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;New_date&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;201901&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;202006&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;202112&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 10:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856421#M338388</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2023-01-31T10:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting year and month from date9. date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856425#M338390</link>
      <description>&lt;P&gt;got solution from ChatGPT&lt;/P&gt;
&lt;PRE&gt;data example;
   input date :date9.;
   year_month = put(date, yymmn6.);
   format date date9.;
   format year_month yymmn6.;
   cards;
   20AUG2017
   ;
run;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jan 2023 10:40:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856425#M338390</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2023-01-31T10:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting year and month from date9. date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856431#M338393</link>
      <description>&lt;P&gt;The PUT not needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
   input date :date9.;
   format date yymmn6.;
   cards;
   20AUG2017
   ;
&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;All you have to do is change the format on DATE. No need to create a new variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 11:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856431#M338393</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-31T11:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting year and month from date9. date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856433#M338394</link>
      <description>Thank you so much</description>
      <pubDate>Tue, 31 Jan 2023 11:29:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856433#M338394</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2023-01-31T11:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting year and month from date9. date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856441#M338398</link>
      <description>&lt;P&gt;I add that ChatGPT did not give you the best answer, it did not give you the easiest answer, and it gave you an answer that will cause difficulties if you need to perform arithmetic or logical operations on these month values (because these month values are now character, and you can't do math easily on character strings).&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 12:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856441#M338398</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-31T12:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting year and month from date9. date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856451#M338404</link>
      <description>&lt;P&gt;Thank you noted&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 12:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856451#M338404</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2023-01-31T12:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting year and month from date9. date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856467#M338409</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I add that ChatGPT did not give you the best answer, it did not give you the easiest answer, and it gave you an answer that will cause difficulties if you need to perform arithmetic or logical operations on these month values (because these month values are now character, and you can't do math easily on character strings).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not to mention the incorrect FORMAT statement it suggested, attempting to apply a numeric format to a character variable:&lt;/P&gt;
&lt;PRE&gt;11    data example;
12       input date :date9.;
13       year_month = put(date, yymmn6.);
14       format date date9.;
15       format year_month yymmn6.;
                           &lt;FONT color="#FF0000"&gt;-------
                           48
ERROR 48-59: The format $YYMMN was not found or could not be loaded.&lt;/FONT&gt;

16       cards;

&lt;FONT color="#3366FF"&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/FONT&gt;
&lt;FONT color="#008000"&gt;WARNING: The data set WORK.EXAMPLE may be incomplete.  When this step was stopped there were 0 observations and 2 variables.&lt;/FONT&gt;
&lt;FONT color="#3366FF"&gt;NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds
&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jan 2023 14:04:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856467#M338409</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-01-31T14:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting year and month from date9. date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856647#M338472</link>
      <description>&lt;P&gt;I unmarked the ChatGPT answer as solution and instead selected the one from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ChatGPT is an amazing tool...but when it comes to answering precise questions, &lt;A href="https://blogs.sas.com/content/sascom/2023/01/17/chatgpt-hot-takes/" target="_self"&gt;it will simply make stuff up&lt;/A&gt;. I don't mind people trying it and sharing their experience on the community, but let's not help train the model with wrong/suboptimal answers.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 13:31:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856647#M338472</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2023-02-01T13:31:17Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting year and month from date9. date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856648#M338473</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was thinking the same about ChatGPT learning from wrong or sub-optimal answers. In addition, there are a lot of SAS users who think that if they want to change a format, a new variable is needed! I see this all the time in the people I work with, and with data sets of potentially millions of records and possibly hundreds of variables, creating one new variable is a lot of work for the computer and a lot more disk space, not to mention the problems caused by converting a numeric date value into a character string (as ChatGPT is recommending and which I objected to).&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 13:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-year-and-month-from-date9-date/m-p/856648#M338473</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-01T13:45:45Z</dc:date>
    </item>
  </channel>
</rss>

