<?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 Convert date to character and group them by substr in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539056#M148479</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently encountering a problem, I have an attribute date, the variable is a date type and the format is like 01MAY2018.&lt;/P&gt;&lt;P&gt;I want to use substr to extract only the month ie.May for this attribute for future analysis; however, sas told me that I need to convert data type first, but I couldn't find the way to convert this specific format to a character variable. Any thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot&lt;/P&gt;</description>
    <pubDate>Wed, 27 Feb 2019 17:07:37 GMT</pubDate>
    <dc:creator>ForrestYao</dc:creator>
    <dc:date>2019-02-27T17:07:37Z</dc:date>
    <item>
      <title>convert date type to character and use substr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539057#M148460</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently encountering a problem, I have an attribute date, the variable is a date type and the format is like 01MAY2018.&lt;/P&gt;&lt;P&gt;I want to use substr to extract only the month ie.May for this attribute for future analysis; however, sas told me that I need to convert data type first, but I couldn't find the way to convert this specific format to a character variable. Any thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 17:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539057#M148460</guid>
      <dc:creator>ForrestYao</dc:creator>
      <dc:date>2019-02-27T17:10:07Z</dc:date>
    </item>
    <item>
      <title>Convert date to character and group them by substr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539056#M148479</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently encountering a problem, I have an attribute date, the variable is a date type and the format is like 01MAY2018.&lt;/P&gt;&lt;P&gt;I want to use substr to extract only the month ie.May for this attribute for future analysis; however, sas told me that I need to convert data type first, but I couldn't find the way to convert this specific format to a character variable. Any thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 17:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539056#M148479</guid>
      <dc:creator>ForrestYao</dc:creator>
      <dc:date>2019-02-27T17:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: convert date type to character and use substr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539061#M148461</link>
      <description>&lt;P&gt;Once a variable is defined as numeric, it stays numeric forever.&amp;nbsp; So when you say it's a "date type" that probably means it's a numeric value on SAS's date scale and cannot be transformed into a character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can fairly easily create a character variable, based on the date's value.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;char_mon = put(datevar, monname.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;char_mon = substr(put(datevar, date9.), 3, 3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a reference that might be helpful, depending on what it means to extract the month only:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201049.htm" target="_blank" rel="noopener"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201049.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 17:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539061#M148461</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-27T17:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: convert date type to character and use substr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539064#M148462</link>
      <description>&lt;P&gt;Thanks a lot, yeah, using your method successfully extracts only the month part and convert it to the character variable.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 17:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539064#M148462</guid>
      <dc:creator>ForrestYao</dc:creator>
      <dc:date>2019-02-27T17:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date to character and group them by substr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539083#M148480</link>
      <description>&lt;P&gt;Hi ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You try your query using the below example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; x&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
dt &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;symget&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'runasofdate'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
rndt &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"'"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;dt&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"'"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
call &lt;SPAN class="token function"&gt;symput&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'rndt'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;rndt&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
mnth &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;substr&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;dt&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;6&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
call &lt;SPAN class="token function"&gt;symput&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'m_key'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;strip&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;mnth&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ashok Arunachalam&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 18:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539083#M148480</guid>
      <dc:creator>Ashok3395</dc:creator>
      <dc:date>2019-02-27T18:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date to character and group them by substr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539089#M148481</link>
      <description>&lt;P&gt;You can use a combination of the PUT function (converts numeric to character) with the SUBSTR function to pull out only the month from the formatted date value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;input dt date9.;&lt;BR /&gt;format dt date9.;&lt;BR /&gt;month=SUBSTR(PUT(dt,date9.),3,3);&lt;BR /&gt;cards;&lt;BR /&gt;01MAY2018&lt;BR /&gt;01JUN2018&lt;BR /&gt;01JUL2018&lt;BR /&gt;01AUG2018&lt;BR /&gt;01SEP2018&lt;BR /&gt;01OCT2018&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 19:04:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539089#M148481</guid>
      <dc:creator>jebjur</dc:creator>
      <dc:date>2019-02-27T19:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date to character and group them by substr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539131#M148486</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply, it works!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 20:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-date-type-to-character-and-use-substr/m-p/539131#M148486</guid>
      <dc:creator>ForrestYao</dc:creator>
      <dc:date>2019-02-27T20:48:50Z</dc:date>
    </item>
  </channel>
</rss>

