<?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: Invalid third argument to function SUBSTR in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Invalid-third-argument-to-function-SUBSTR/m-p/547647#M151781</link>
    <description>&lt;P&gt;We'd prefer the last name left unchanged.&lt;/P&gt;</description>
    <pubDate>Mon, 01 Apr 2019 15:52:42 GMT</pubDate>
    <dc:creator>elli444</dc:creator>
    <dc:date>2019-04-01T15:52:42Z</dc:date>
    <item>
      <title>Invalid third argument to function SUBSTR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Invalid-third-argument-to-function-SUBSTR/m-p/547639#M151776</link>
      <description>&lt;P&gt;I don't know how to revise the third argument that is producing the error message. It is referring to the line bolded below. Any suggestions much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if indexw(name_last,' AKA ') then do;&lt;BR /&gt;alias=strip(strip(alias)||"/"||substr(name_last,(indexw(name_last,'AKA')+4)));&lt;BR /&gt;if index(alias,"/")=1 then alias=compress(alias,"/");&lt;BR /&gt;&lt;STRONG&gt;name_last=substr(name_last,1,indexw(name_last,'AKA')-1);&lt;/STRONG&gt;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 15:29:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Invalid-third-argument-to-function-SUBSTR/m-p/547639#M151776</guid>
      <dc:creator>elli444</dc:creator>
      <dc:date>2019-04-01T15:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid third argument to function SUBSTR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Invalid-third-argument-to-function-SUBSTR/m-p/547643#M151778</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268839"&gt;@elli444&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This happens if AKA is the first word in last_name. Then indexw returnns 1, and the third argument becomes 0, which is illegal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What should happen in this case? - last_name left unchanged or last_name set empty?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 15:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Invalid-third-argument-to-function-SUBSTR/m-p/547643#M151778</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-04-01T15:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid third argument to function SUBSTR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Invalid-third-argument-to-function-SUBSTR/m-p/547647#M151781</link>
      <description>&lt;P&gt;We'd prefer the last name left unchanged.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 15:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Invalid-third-argument-to-function-SUBSTR/m-p/547647#M151781</guid>
      <dc:creator>elli444</dc:creator>
      <dc:date>2019-04-01T15:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid third argument to function SUBSTR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Invalid-third-argument-to-function-SUBSTR/m-p/547697#M151799</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268839"&gt;@elli444&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this small modification (check for indexw &amp;gt; 1) will work. The problem with your code is that indexw ignores blanks. Even if you specify indexw('&amp;nbsp; AKA&amp;nbsp; '), it treats is as 'AKA', so the condition vill be true also if name_last starts with AKA.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
	infile datalines truncover;
	input name_last $char50.;
datalines;
Hansen AKA Hans
AKA Dummy
Saint George AKA Dragon
;

data want; set have;
	if indexw(name_last,'AKA') &amp;gt; 1 then do;
		name_last=substr(name_last,1,indexw(name_last,'AKA')-1);
	end;	
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="ln.gif" style="width: 271px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28375iFDC136216792EE14/image-size/large?v=v2&amp;amp;px=999" role="button" title="ln.gif" alt="ln.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 18:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Invalid-third-argument-to-function-SUBSTR/m-p/547697#M151799</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-04-01T18:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid third argument to function SUBSTR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Invalid-third-argument-to-function-SUBSTR/m-p/547885#M151874</link>
      <description>&lt;P&gt;Use SUBSTRN() instead of SUBSTR() .&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 13:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Invalid-third-argument-to-function-SUBSTR/m-p/547885#M151874</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-04-02T13:02:47Z</dc:date>
    </item>
  </channel>
</rss>

