<?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: delete the strings beginning at 'DEAD' in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546596#M151355</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The note is caused by an illegal third parameter to substr. If then string "DEAD" is not found, find returns 0, and then your substring vill be&amp;nbsp;substr(name,1,0), which is illegal. This removes the notes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=found); set have;
 	found = find(name,'DEAD');
	if found &amp;gt; 1 then name=substr(name,1,found-1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If found = 0 then name remains unchanged.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Mar 2019 17:01:51 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2019-03-27T17:01:51Z</dc:date>
    <item>
      <title>delete the strings beginning at 'DEAD'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546563#M151337</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how can I delete the strings beginning&amp;nbsp;at 'DEAD'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  infile datalines truncover;
  input name $100.;
  datalines;
ABB 'A' (LON) DEAD - DELIST 06/04/98
ABB 'B' (LON) DEAD - DELISTED
ABB AG (XSQ) DEAD - 19/06/99
ABB BF (LON) DEAD - DEAD
ABBEY NATIONAL DEAD - T/O SEE 702853
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I expect to get&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ABB 'A' (LON) 
ABB 'B' (LON) 
ABB AG (XSQ) 
ABB BF (LON) 
ABBEY NATIONAL&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 15:44:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546563#M151337</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2019-03-27T15:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: delete the strings beginning at 'DEAD'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546566#M151338</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  infile datalines truncover;
  input name $100.;
  datalines;
ABB 'A' (LON) DEAD - DELIST 06/04/98
ABB 'B' (LON) DEAD - DELISTED
ABB AG (XSQ) DEAD - 19/06/99
ABB BF (LON) DEAD - DEAD
ABBEY NATIONAL DEAD - T/O SEE 702853
;
run;

data want;
set have;
want=substr(name,1,findw(name,'DEAD')-1);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 15:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546566#M151338</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T15:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: delete the strings beginning at 'DEAD'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546585#M151345</link>
      <description>&lt;P&gt;Dear &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks, the code works on the sample,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;however, I get some 'NOTE' when I process the main dataset by following codes,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
Set Step9.Datastream_gb_Step23;
NAME_Step23_1=substr(NAME_Step23,1,findw(NAME_Step23,'DEAD')-1);
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and one of them is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Invalid third argument to function SUBSTR at line 2591 column 15.
Type=13283U NAME=INTERCEDE GROUP COMPANY_NAME=INTERCEDE GROUP PLC COMPANY_NAME_1=INTERCEDE GROUP PLC.
COMPANY_NAME___SHORT=INTERCEDE GROUP PLC PREVIOUS_NAME=  GEOGRAPHIC_DESCR_=GB MNEMONIC=IGP
EQUITIES_STATUS=ACT. ISIN_CODE=GB0003287249 ISIN_NUMBER=GB0003287249 ISIN_ISSUER_CTRY=GB
ISIN_CODE_THAI_FB=  QUOTE_INDICATOR=P ISIN_NUMBER_1=GB0003287249 INACTIVE_DATE=.
NAME_Step1=INTERCEDE GROUP COMPANY_NAME_Step1=INTERCEDE GROUP PLC
COMPANY_NAME_1_Step1=INTERCEDE GROUP PLC. COMPANY_NAME___SHORT_Step1=INTERCEDE GROUP PLC
PREVIOUS_NAME_Step1=  NAME_Step2=INTERCEDE GROUP chflagNAME_2v1=0
COMPANY_NAME_Step2=INTERCEDE GROUP PLC chflagCOMPANY_NAME_2v1=0
COMPANY_NAME_1_Step2=INTERCEDE GROUP PLC. chflagCOMPANY_NAME_1_2v1=0
COMPANY_NAME___SHORT_Step2=INTERCEDE GROUP PLC chflagCOMPANY_NAME___SHORT_2v1=0 PREVIOUS_NAME_Step2=
chflagPREVIOUS_NAME_2v1=0 NAME_Step21=INTERCEDE GROUP chflagNAME_21v2=0
COMPANY_NAME_Step21=INTERCEDE GROUP PLC chflagCOMPANY_NAME_21v2=0
COMPANY_NAME_1_Step21=INTERCEDE GROUP PLC. chflagCOMPANY_NAME_1_21v2=0
COMPANY_NAME___SHORT_Step21=INTERCEDE GROUP PLC chflagCOMPANY_NAME___SHORT_21v2=0
PREVIOUS_NAME_Step21=  chflagPREVIOUS_NAME_21v2=0 NAME_Step22=INTERCEDE GROUP chflagNAME_22v21=0
COMPANY_NAME_Step22=INTERCEDE GROUP PLC chflagCOMPANY_NAME_22v21=0
COMPANY_NAME_1_Step22=INTERCEDE GROUP PLC. chflagCOMPANY_NAME_1_22v21=0
COMPANY_NAME___SHORT_Step22=INTERCEDE GROUP PLC chflagCOMPANY_NAME___SHORT_22v21=0
PREVIOUS_NAME_Step22=  chflagPREVIOUS_NAME_22v21=0 NAME_Step23=INTERCEDE GROUP cflagNAME_22vs23=0
COMPANY_NAME_Step23=INTERCEDE GROUP PLC cflagCOMPANY_NAME_22vs23=0
COMPANY_NAME_1_Step23=INTERCEDE GROUP PLC. cflagCOMPANY_NAME_1_22vs23=0
COMPANY_NAME___SHORT_Step23=INTERCEDE GROUP PLC cflagCOMPANY_NAME___SHORT_22vs23=0
PREVIOUS_NAME_Step23=  cflagPREVIOUS_NAME_22vs23=0 NAME_Step23_1=INTERCEDE GROUP _ERROR_=1 _N_=7&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I fix this?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 16:26:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546585#M151345</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2019-03-27T16:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: delete the strings beginning at 'DEAD'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546590#M151350</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp; &amp;nbsp;It's difficult to guess what your real is. The assumption i went with is that your sample is good representative of your real.&lt;/P&gt;
&lt;P&gt;Try FIND instead of FINDW and experiment&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
want=substr(name,1,find(name,'DEAD')-1);
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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 16:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546590#M151350</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T16:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: delete the strings beginning at 'DEAD'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546592#M151352</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp; &amp;nbsp;May be some of the records do not have substr 'DEAD' in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So perhaps a conditional construct like this??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if find(name,'DEAD')&amp;gt;0 then want=substr(name,1,find(name,'DEAD')-1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Mar 2019 16:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546592#M151352</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T16:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: delete the strings beginning at 'DEAD'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546593#M151353</link>
      <description>&lt;P&gt;You need to include examples that do NOT contain the text DEAD so that solutions can be made that handle that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  infile datalines truncover;
  input name $100.;
  datalines;
ABB 'A' (LON) DEAD - DELIST 06/04/98
ABB 'B' (LON) DEAD - DELISTED
ABB AG (XSQ) DEAD - 19/06/99
No Change
ABB BF (LON) DEAD - DEAD
ABBEY NATIONAL DEAD - T/O SEE 702853
DEADHEAD Alive
;

data want;
  set have;
  if index(name,' DEAD ') then
    name=substrn(name,1,index(name,' DEAD '))
  ;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    name

 1     ABB 'A' (LON)
 2     ABB 'B' (LON)
 3     ABB AG (XSQ)
 4     No Change
 5     ABB BF (LON)
 6     ABBEY NATIONAL
 7     DEADHEAD Alive
&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Mar 2019 17:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546593#M151353</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-27T17:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: delete the strings beginning at 'DEAD'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546596#M151355</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The note is caused by an illegal third parameter to substr. If then string "DEAD" is not found, find returns 0, and then your substring vill be&amp;nbsp;substr(name,1,0), which is illegal. This removes the notes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=found); set have;
 	found = find(name,'DEAD');
	if found &amp;gt; 1 then name=substr(name,1,found-1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If found = 0 then name remains unchanged.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 17:01:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546596#M151355</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-03-27T17:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: delete the strings beginning at 'DEAD'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546643#M151379</link>
      <description>&lt;P&gt;You can take advantage of a unique property of the SUBSTR function - namely that it can be on the left of an assignment statement.&amp;nbsp; For instance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; substr(name,15)=' ';&lt;/P&gt;
&lt;P&gt;replaces all characters starting at position 15 in NAME by blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case&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 $100.;
  datalines;
ABB 'A' (LON) DEAD - DELIST 06/04/98
ABB 'B' (LON) DEAD - DELISTED
ABB AG (XSQ) DEAD - 19/06/99
ABB BF (LON) DEAD - DEAD
ABBEY NATIONAL DEAD - T/O SEE 702853
;
run;

data want;
  set have;
  substr(name,indexw(name,'DEAD'))=' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited additional comment:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By using the INDEXW function to find the character position, instead of the INDEX function, you won't get false positives from words like 'UNDEAD' or 'DEADLY'.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 19:24:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546643#M151379</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-03-27T19:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: delete the strings beginning at 'DEAD'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546663#M151392</link>
      <description>This will also give the "Invalid argument to substr" note, if the string "DEAD" is not found.</description>
      <pubDate>Wed, 27 Mar 2019 19:51:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delete-the-strings-beginning-at-DEAD/m-p/546663#M151392</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-03-27T19:51:56Z</dc:date>
    </item>
  </channel>
</rss>

