<?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: Use of substr function inside macro code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-of-substr-function-inside-macro-code/m-p/439553#M109701</link>
    <description>&lt;P&gt;Both of you were right. I really appreciate your help. God bless you. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Feb 2018 01:33:09 GMT</pubDate>
    <dc:creator>Sejin</dc:creator>
    <dc:date>2018-02-23T01:33:09Z</dc:date>
    <item>
      <title>Use of substr function inside macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-substr-function-inside-macro-code/m-p/439530#M109683</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having a problem while writing a macro code. I want to use substr function inside th macro.&lt;/P&gt;&lt;P&gt;Here is an example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro name (timej);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let year=substr("&amp;amp;timej",1,4);&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table table2 as&lt;/P&gt;&lt;P&gt;select * from table&amp;amp;year;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%name (19901231);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So macro variable timej is 8-digit numeric value which implies year, month, date.&lt;/P&gt;&lt;P&gt;I need to take apart the first 4 digits from the variable.&lt;/P&gt;&lt;P&gt;The above code doesn't work. I tried %substr or other things that I can think of, but never worked properly.&lt;/P&gt;&lt;P&gt;And I want to do it&amp;nbsp;INSIDE the macro code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anyone give some advices for this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for reading my thread.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 00:43:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-substr-function-inside-macro-code/m-p/439530#M109683</guid>
      <dc:creator>Sejin</dc:creator>
      <dc:date>2018-02-23T00:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Use of substr function inside macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-substr-function-inside-macro-code/m-p/439534#M109686</link>
      <description>&lt;P&gt;You can either use the macro function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%let year=%substr(&amp;amp;timej,1,4);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or the sas function via the %sysfunc macro function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;%let year=%sysfunc(substr(&amp;amp;timej,1,4));&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any case, no quotes should be used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 00:57:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-substr-function-inside-macro-code/m-p/439534#M109686</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-02-23T00:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Use of substr function inside macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-substr-function-inside-macro-code/m-p/439537#M109689</link>
      <description>&lt;P&gt;below code should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro name (timej);

 

%let year= %sysfunc(substr(&amp;amp;timej,1,4));
%put &amp;amp;year;

proc sql;

create table table2 as

select * from table&amp;amp;year;

quit;

 

%mend;

 

%name(19901231);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Feb 2018 00:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-substr-function-inside-macro-code/m-p/439537#M109689</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-02-23T00:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Use of substr function inside macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-of-substr-function-inside-macro-code/m-p/439553#M109701</link>
      <description>&lt;P&gt;Both of you were right. I really appreciate your help. God bless you. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 01:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-of-substr-function-inside-macro-code/m-p/439553#M109701</guid>
      <dc:creator>Sejin</dc:creator>
      <dc:date>2018-02-23T01:33:09Z</dc:date>
    </item>
  </channel>
</rss>

