<?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: %SUBSTR is out of range warning in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747521#M234626</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To take the substring starting at the 10th character, just omit the third argument of the %SUBSTR function, which does &lt;EM&gt;not&lt;/EM&gt; specify the position of the last character of the substring to be extracted, but the length of the substring (see &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n0nq1hkovbu54en1h78i6ci7gz51.htm" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt;)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let trans_table_sql=%substr(&amp;amp;trans_table.,10);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 12 Jun 2021 07:48:43 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-06-12T07:48:43Z</dc:date>
    <item>
      <title>%SUBSTR is out of range warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747517#M234623</link>
      <description>&lt;P&gt;If I execute the code below, I'm getting the out of range&amp;nbsp; warning with %SUBSTR. Any help to fix this warning?&lt;/P&gt;
&lt;P&gt;Also I would like to know if there is way to replace tranwrd with parsing function in this same program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%* Set example input values ;
%let _output0=IFRSITSS.META_DATA;
%let _output1=IFRSITSS.INSURANCE;
%let _output2=IFRSITSS.AUDIT_TRAIL;

%* Set the FIXED values ;
%let meta_table=IFRSITSS.META_DATA;
%let audit_table=IFRSITSS.AUDIT_TRAIL;

%* Calculate TRANS_TABLE by removing the FIXED table names from the list of all three ;
%let trans_table=&amp;amp;_output0 &amp;amp;_output1 &amp;amp;_output2;
%let trans_table=%sysfunc(tranwrd(&amp;amp;trans_table,&amp;amp;meta_table,));
%let trans_table=%sysfunc(tranwrd(&amp;amp;trans_table,&amp;amp;audit_table,));
%let trans_table_sql=%substr(&amp;amp;trans_table.,10,%length(&amp;amp;trans_table.));

%put #### Trans_Table is &amp;amp;Trans_Table.;
%put #### Trans_Table_sql is &amp;amp;Trans_Table_sql.;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;27         %let _output0=IFRSITSS.META_DATA;
28         %let _output1=IFRSITSS.INSURANCE;
29         %let _output2=IFRSITSS.AUDIT_TRAIL;
30         
31         %* Set the FIXED values ;
32         %let meta_table=IFRSITSS.META_DATA;
33         %let audit_table=IFRSITSS.AUDIT_TRAIL;
34         
35         %* Calculate TRANS_TABLE by removing the FIXED table names from the list of all three ;
36         %let trans_table=&amp;amp;_output0 &amp;amp;_output1 &amp;amp;_output2;
37         %let trans_table=%sysfunc(tranwrd(&amp;amp;trans_table,&amp;amp;meta_table,));
38         %let trans_table=%sysfunc(tranwrd(&amp;amp;trans_table,&amp;amp;audit_table,));
39         %let trans_table_sql=%substr(&amp;amp;trans_table.,10,%length(&amp;amp;trans_table.));
WARNING: Argument 3 to macro function %SUBSTR is out of range.
40         
41         %put #### Trans_Table is &amp;amp;Trans_Table.;
#### Trans_Table is IFRSITSS.INSURANCE
42         %put #### Trans_Table_sql is &amp;amp;Trans_Table_sql.;
#### Trans_Table_sql is INSURANCE&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Jun 2021 07:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747517#M234623</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-06-12T07:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: %SUBSTR is out of range warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747521#M234626</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To take the substring starting at the 10th character, just omit the third argument of the %SUBSTR function, which does &lt;EM&gt;not&lt;/EM&gt; specify the position of the last character of the substring to be extracted, but the length of the substring (see &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n0nq1hkovbu54en1h78i6ci7gz51.htm" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt;)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let trans_table_sql=%substr(&amp;amp;trans_table.,10);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Jun 2021 07:48:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747521#M234626</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-06-12T07:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: %SUBSTR is out of range warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747522#M234627</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;Thank you. Another question is can we deal this program parsing function instead of tranwrd?&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jun 2021 08:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747522#M234627</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-06-12T08:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: %SUBSTR is out of range warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747526#M234629</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Another question is can we deal this program parsing function instead of tranwrd?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How about using &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0r8h2fa8djqf1n1cnenrvm573br.htm" target="_blank" rel="noopener"&gt;PRXCHANGE&lt;/A&gt; and &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1nhhymw6gxixvn1johcfl6kaygw.htm" target="_blank" rel="noopener"&gt;%SCAN&lt;/A&gt;?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let trans_table_sql=%scan(%sysfunc(prxchange(s/&amp;amp;meta_table|&amp;amp;audit_table//,-1,&amp;amp;trans_table)),2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here, the effect of PRXCHANGE is similar to that of TRANWRD in your code: It deletes &lt;FONT face="courier new,courier"&gt;&amp;amp;meta_table&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;&amp;amp;audit_table&lt;/FONT&gt; from &lt;FONT face="courier new,courier"&gt;&amp;amp;trans_table&lt;/FONT&gt;.&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;Finally, %SCAN selects the second "word" from the resulting string, using default delimiters (which include the period, "&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;.&lt;/FONT&gt;&lt;SPAN style="font-family: inherit;"&gt;") as word delimiters.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jun 2021 10:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747526#M234629</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-06-12T10:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: %SUBSTR is out of range warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747528#M234631</link>
      <description>Great.Don't we get the same results even if we remove %scan function in&lt;BR /&gt;your proposed code?&lt;BR /&gt;</description>
      <pubDate>Sat, 12 Jun 2021 09:54:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747528#M234631</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-06-12T09:54:24Z</dc:date>
    </item>
    <item>
      <title>Re: %SUBSTR is out of range warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747529#M234632</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Great.Don't we get the same results even if we remove %scan function in&lt;BR /&gt;your proposed code?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not with your sample data:&lt;/P&gt;
&lt;PRE&gt;122  %put Without '%SCAN': %sysfunc(prxchange(s/&amp;amp;meta_table|&amp;amp;audit_table//,-1,&amp;amp;trans_table));
Without '%SCAN':  &lt;STRONG&gt;IFRSITSS.INSURANCE&lt;/STRONG&gt;
123  %put With '%SCAN': %scan(%sysfunc(prxchange(s/&amp;amp;meta_table|&amp;amp;audit_table//,-1,&amp;amp;trans_table)),2);
With '%SCAN': &lt;STRONG&gt;INSURANCE&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;(Note the inserted minus sign in the second argument of the PRXCHANGE function.)&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jun 2021 10:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747529#M234632</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-06-12T10:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: %SUBSTR is out of range warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747545#M234641</link>
      <description>Why we need that minus sign in second argument?&lt;BR /&gt;</description>
      <pubDate>Sat, 12 Jun 2021 15:40:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747545#M234641</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-06-12T15:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: %SUBSTR is out of range warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747547#M234643</link>
      <description>&lt;P&gt;If you want to extract the member name from a dataset reference in LIBREF.MEMNAME form use the %SCAN() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let memname=%scan(&amp;amp;dsname,-1,.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note this will work whether or not the DSNAME macro variable has the libref prefix or not.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jun 2021 16:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747547#M234643</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-12T16:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: %SUBSTR is out of range warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747548#M234644</link>
      <description>&lt;P&gt;You appear to be trying to get the member name from a dataset reference.&amp;nbsp; Just use %SCAN().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let trans_table_sql=%scan(&amp;amp;trans_table.,-1,.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will take everything after the last period.&amp;nbsp; If there is no period (you are using a one level name to reference a WORK dataset) then the whole string is returned.&amp;nbsp; Which is what you want.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jun 2021 16:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747548#M234644</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-12T16:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: %SUBSTR is out of range warning</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747553#M234648</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Why we need that minus sign in second argument?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since we need &lt;EM&gt;two&lt;/EM&gt; replacements (in your example), PRXCHANGE must apply the regular expression to the remaining string after the first matched substring has been replaced (i.e. deleted). The &lt;FONT face="courier new,courier"&gt;-1&lt;/FONT&gt; in the second argument tells SAS to continue the replacements until the end of the string in the third argument is reached, so it would work for more than two replacements as well.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jun 2021 16:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTR-is-out-of-range-warning/m-p/747553#M234648</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-06-12T16:50:05Z</dc:date>
    </item>
  </channel>
</rss>

