<?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: Extract from Character variable in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-from-Character-variable/m-p/924702#M44627</link>
    <description>&lt;P&gt;Let's parse a bit of what SAS is going to do with a character value of 202103.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;year = year(yrmth);&lt;/PRE&gt;
&lt;P&gt;The year function expects a numeric value that hopefully is a date value. So '202103' gets turned into a numeric value of 202103 by SAS attempting to correct data to the proper expected form (generating &lt;BR /&gt;NOTE: Character values have been converted to numeric values at the places given by:&lt;BR /&gt;(Line):(Column). )&lt;BR /&gt;Since the number value 202103 corresponds to 04MAY2513 the value of the variable year is 2513.&lt;/P&gt;
&lt;P&gt;The QTR function then does the same conversion to numeric for YrMth, resulting in the same 04May2513 date, and reports the quarter is 2 (May being in the second quarter) and Quarter is "Q2".&lt;/P&gt;
&lt;P&gt;The Year and Month functions repeat the same conversion so Curr_month ends up as 251305 (May being the 5th month).&lt;/P&gt;
&lt;P&gt;I can't guess what value Month2 has because we don't have the format $mth but it would be based on May or '05' .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Apr 2024 16:55:52 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-04-17T16:55:52Z</dc:date>
    <item>
      <title>Extract from Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-from-Character-variable/m-p/924641#M44618</link>
      <description>&lt;P&gt;I am trying to extract year, quarter and month from YrMth with value that looks like 202103.&amp;nbsp; It is a character format and the below isn't working:&lt;/P&gt;
&lt;PRE&gt;&lt;BR /&gt;year = year(YrMth);&lt;BR /&gt;Quarter = "Q" || put(QTR(YrMth),$1.); &lt;BR /&gt;yr = put (year,z4.); &lt;BR /&gt;&lt;BR /&gt;curr_mnth = put(year(YrMth),z4.) || put(month(YrMth),z2.);&lt;BR /&gt;month2=put(put(month(YrMth),z2.), $mth.); &amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 05:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-from-Character-variable/m-p/924641#M44618</guid>
      <dc:creator>bhca60</dc:creator>
      <dc:date>2024-04-17T05:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Extract from Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-from-Character-variable/m-p/924642#M44619</link>
      <description>&lt;P&gt;The YEAR, QTR and MTH functions expect a SAS date value, which has to be numeric, not character (count of days with 1960-01-01 as day zero).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How did you define the $MTH format used in the last statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post the complete (all code and messages) log from your step.&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/290946"&gt;@bhca60&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to extract year, quarter and month from YrMth with value that looks like 202103.&amp;nbsp; It is a character format and the below isn't working:&lt;/P&gt;
&lt;PRE&gt;&lt;BR /&gt;year = year(YrMth);&lt;BR /&gt;Quarter = "Q" || put(QTR(YrMth),$1.); &lt;BR /&gt;yr = put (year,z4.); &lt;BR /&gt;&lt;BR /&gt;curr_mnth = put(year(YrMth),z4.) || put(month(YrMth),z2.);&lt;BR /&gt;month2=put(put(month(YrMth),z2.), $mth.); &amp;nbsp;&lt;/PRE&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>Wed, 17 Apr 2024 05:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-from-Character-variable/m-p/924642#M44619</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-04-17T05:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: Extract from Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-from-Character-variable/m-p/924644#M44620</link>
      <description>&lt;P&gt;How about using the INPUT function together with appropriate INFORMAT, like so:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  yrmth = "202103";
  yrmth_sasdate = input(yrmth, yymmn6.);
  year = year(yrmth_sasdate);
  qtr = qtr(yrmth_sasdate);
  month = month(yrmth_sasdate);
  format yrmth_sasdate date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you have a SAS date variable and you can use all the functions that work with a SAS date.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 06:12:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-from-Character-variable/m-p/924644#M44620</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2024-04-17T06:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Extract from Character variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-from-Character-variable/m-p/924702#M44627</link>
      <description>&lt;P&gt;Let's parse a bit of what SAS is going to do with a character value of 202103.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;year = year(yrmth);&lt;/PRE&gt;
&lt;P&gt;The year function expects a numeric value that hopefully is a date value. So '202103' gets turned into a numeric value of 202103 by SAS attempting to correct data to the proper expected form (generating &lt;BR /&gt;NOTE: Character values have been converted to numeric values at the places given by:&lt;BR /&gt;(Line):(Column). )&lt;BR /&gt;Since the number value 202103 corresponds to 04MAY2513 the value of the variable year is 2513.&lt;/P&gt;
&lt;P&gt;The QTR function then does the same conversion to numeric for YrMth, resulting in the same 04May2513 date, and reports the quarter is 2 (May being in the second quarter) and Quarter is "Q2".&lt;/P&gt;
&lt;P&gt;The Year and Month functions repeat the same conversion so Curr_month ends up as 251305 (May being the 5th month).&lt;/P&gt;
&lt;P&gt;I can't guess what value Month2 has because we don't have the format $mth but it would be based on May or '05' .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 16:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-from-Character-variable/m-p/924702#M44627</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-17T16:55:52Z</dc:date>
    </item>
  </channel>
</rss>

