<?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 Trouble with SUBSTR function in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/626936#M20456</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to extract the month from a date value that looks like this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date1&lt;/P&gt;
&lt;P&gt;20080201&lt;/P&gt;
&lt;P&gt;20080301&lt;/P&gt;
&lt;P&gt;20080401&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I want to create a new variable that is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date2&lt;/P&gt;
&lt;P&gt;02&lt;/P&gt;
&lt;P&gt;03&lt;/P&gt;
&lt;P&gt;04&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So i tried using&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date2=SUBSTR(Date1, 5, 2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it did not work. Can you help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Mon, 24 Feb 2020 18:06:05 GMT</pubDate>
    <dc:creator>marleeakerson</dc:creator>
    <dc:date>2020-02-24T18:06:05Z</dc:date>
    <item>
      <title>Trouble with SUBSTR function</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/626936#M20456</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to extract the month from a date value that looks like this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date1&lt;/P&gt;
&lt;P&gt;20080201&lt;/P&gt;
&lt;P&gt;20080301&lt;/P&gt;
&lt;P&gt;20080401&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I want to create a new variable that is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date2&lt;/P&gt;
&lt;P&gt;02&lt;/P&gt;
&lt;P&gt;03&lt;/P&gt;
&lt;P&gt;04&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So i tried using&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date2=SUBSTR(Date1, 5, 2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it did not work. Can you help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 24 Feb 2020 18:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/626936#M20456</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2020-02-24T18:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with SUBSTR function</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/626937#M20457</link>
      <description>Put Date1 into a char variable before you substr.</description>
      <pubDate>Mon, 24 Feb 2020 18:10:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/626937#M20457</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2020-02-24T18:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with SUBSTR function</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/626938#M20458</link>
      <description>&lt;P&gt;How do I do that?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 18:11:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/626938#M20458</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2020-02-24T18:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with SUBSTR function</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/626939#M20459</link>
      <description>To convert numeric values to character, use the PUT function</description>
      <pubDate>Mon, 24 Feb 2020 18:13:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/626939#M20459</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2020-02-24T18:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with SUBSTR function</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/626940#M20460</link>
      <description>&lt;P&gt;phrases like 'it did not work' does not help us much. What differs from what you expect? What does the log say?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Help us help you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 18:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/626940#M20460</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-02-24T18:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with SUBSTR function</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/626942#M20462</link>
      <description>&lt;P&gt;Do you have a character variable?&amp;nbsp; Or a numeric?&amp;nbsp; If a numeric does it have date values? Or just numbers like 20,200,801?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input
   @1 date yymmdd8.
   @1 char $8.
   @1 num 
  ;
  format date yymmdd10.;
cards;
20080201
20080301
20080401
;

data want;
  set have;
  month_date = month(date);
  month_char = substr(char,5,2);
  month_num = int(mod(num,1E4)/1E2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                                             month_    month_    month_
Obs          date      char         num       date      char       num

 1     2008-02-01    20080201    20080201       2        02         2
 2     2008-03-01    20080301    20080301       3        03         3
 3     2008-04-01    20080401    20080401       4        04         4&lt;/PRE&gt;
&lt;P&gt;In general it is easier/clearer to work with actual date values.&amp;nbsp; So perhaps you want to convert character or non-date numerics to date first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  month_date = month(date);
  month_char = month(input(char,yymmdd8.));
  month_num = month(input(put(num,z8.),yymmdd8.));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Feb 2020 18:21:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/626942#M20462</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-24T18:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with SUBSTR function</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/627047#M20481</link>
      <description>&lt;P&gt;Since it is a date value (as you posted), just use the month() function.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 21:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-with-SUBSTR-function/m-p/627047#M20481</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-24T21:37:07Z</dc:date>
    </item>
  </channel>
</rss>

