<?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: Identifying and removing part of a string of text in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/m-p/62683#M17848</link>
    <description>Thanks, I will have a look, I just didn't know what kind of functions I needed to read up on</description>
    <pubDate>Wed, 11 Aug 2010 12:20:24 GMT</pubDate>
    <dc:creator>NicolaD</dc:creator>
    <dc:date>2010-08-11T12:20:24Z</dc:date>
    <item>
      <title>Identifying and removing part of a string of text</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/m-p/62681#M17846</link>
      <description>I wasn't sure which forum to post this is, I need code that will work in Information Map Studio and/or Enterprise Guide.&lt;BR /&gt;
&lt;BR /&gt;
I have a list of area names followed by a code in brackets e.g.&lt;BR /&gt;
&lt;BR /&gt;
Leeds (212)&lt;BR /&gt;
Wakefield (213)&lt;BR /&gt;
Kingston-upon-Hull (215)&lt;BR /&gt;
N Lincolnshire (216)&lt;BR /&gt;
&lt;BR /&gt;
...etc&lt;BR /&gt;
&lt;BR /&gt;
I need to use just the area names without the code, but with my limited SAS knowledge, don't know of any syntax to do this. All the area names have the same format as the examples above and can contain spaces, "&amp;amp;" and " - " so I'm looking for code that will search the string and then strip from the open brackets ( to the end, I think I can then use the STRIP function to remove the trailing blank left at the end&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
Nicola</description>
      <pubDate>Wed, 11 Aug 2010 09:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/m-p/62681#M17846</guid>
      <dc:creator>NicolaD</dc:creator>
      <dc:date>2010-08-11T09:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying and removing part of a string of text</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/m-p/62682#M17847</link>
      <description>&lt;P&gt;&lt;EM&gt;Editor's Note:&amp;nbsp; Thanks for the excellent solution.&amp;nbsp; I have added a full code version down below.&amp;nbsp; &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Combining index- and substr-function seems to be a good start:&lt;BR /&gt; name = substr(name, 1, index(name, '(') -1);&lt;BR /&gt; &lt;BR /&gt; Both functions are well documented:&lt;BR /&gt; index: &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/a000212242.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/a000212242.htm&lt;/A&gt;&lt;BR /&gt; substr: &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/a000212264.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/a000212264.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;                                  
input name $1-24;   
cards;
Leeds (212)
Wakefield (213)
Kingston-upon-Hull (215)
N Lincolnshire (216)
;

data two;
   set one;
   length new_name $24;
   new_name=substr(name,1,index(name, '(')-1);
run; 
                                      
proc print;                                
run; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Sep 2016 17:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/m-p/62682#M17847</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2016-09-29T17:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying and removing part of a string of text</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/m-p/62683#M17848</link>
      <description>Thanks, I will have a look, I just didn't know what kind of functions I needed to read up on</description>
      <pubDate>Wed, 11 Aug 2010 12:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/m-p/62683#M17848</guid>
      <dc:creator>NicolaD</dc:creator>
      <dc:date>2010-08-11T12:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying and removing part of a string of text</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/m-p/62684#M17849</link>
      <description>as well as the solution offered by "andreas_id", NicolaD could use the scan() function, because she wants what comes before the first "("....., like&lt;BR /&gt;
   main_part = scan( whole_string, 1, '('  );&lt;BR /&gt;
If there might be a "(" within the real main_part, then this approach won't do. &lt;BR /&gt;
The FIND() function has a "direction of search" feature which may be more helpful.&lt;BR /&gt;
That blank which comes before the "(number)" provides an excellent marker.&lt;BR /&gt;
  main_part = substr( whole_string, 1, find( trim(whole_string), ' ',  -9999) ) ;&lt;BR /&gt;
where that find function should return the position of the blank before the "(number)". As a demo: the code&lt;BR /&gt;
data;&lt;BR /&gt;
  whole_string = 'rt(hjk) yui (567) ' ;&lt;BR /&gt;
  main_part = substr( whole_string, 1, find( trim(whole_string), ' ',  -9999) ) ;&lt;BR /&gt;
  put (_all_)(/=);&lt;BR /&gt;
run;&lt;BR /&gt;
creates the SASlog [pre]43   run;&lt;BR /&gt;
&lt;BR /&gt;
whole_string=rt(hjk) yui (567)&lt;BR /&gt;
main_part=rt(hjk) yui&lt;BR /&gt;
NOTE: The data set WORK.[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Trailing blanks in a variable are normal/unavoidable when stored, and easily removed when the variable is used.  &lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Wed, 11 Aug 2010 12:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/m-p/62684#M17849</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-08-11T12:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying and removing part of a string of text</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/m-p/62685#M17850</link>
      <description>I like regular expressions, so here's a solution that uses a regexp to solve the problem. The regexp is coded so that an area name that is &lt;I&gt;not&lt;/I&gt; followed by a code fails to match. If this is not the desired behavior, use [pre]"/^([^\(]+)/"[/pre] instead.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
	infile datalines truncover;&lt;BR /&gt;
	retain re;&lt;BR /&gt;
&lt;BR /&gt;
	if _N_ = 1 then do;&lt;BR /&gt;
		re = prxparse("/^([^\(]+)\(/");&lt;BR /&gt;
	end;&lt;BR /&gt;
&lt;BR /&gt;
	input areaname $25.;&lt;BR /&gt;
&lt;BR /&gt;
	match = prxmatch(re, areaname);&lt;BR /&gt;
	if match ^= 0 then do;&lt;BR /&gt;
		call prxposn(re, match, start, length);&lt;BR /&gt;
		areaname = substr(areaname, start, length);&lt;BR /&gt;
		put areaname=;&lt;BR /&gt;
	end;&lt;BR /&gt;
	else do;&lt;BR /&gt;
		put 'No match for "' areaname '"';&lt;BR /&gt;
	end;&lt;BR /&gt;
datalines;&lt;BR /&gt;
Leeds (212)&lt;BR /&gt;
Wakefield (213)&lt;BR /&gt;
Kingston-upon-Hull (215)&lt;BR /&gt;
N Lincolnshire (216)&lt;BR /&gt;
Barton-Upon-Humber&lt;BR /&gt;
;;;;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Yields&lt;BR /&gt;
[pre]&lt;BR /&gt;
areaname=Leeds&lt;BR /&gt;
areaname=Wakefield&lt;BR /&gt;
areaname=Kingston-upon-Hull&lt;BR /&gt;
areaname=N Lincolnshire&lt;BR /&gt;
No match for "Barton-Upon-Humber "&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 11 Aug 2010 13:10:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/m-p/62685#M17850</guid>
      <dc:creator>Tim_SAS</dc:creator>
      <dc:date>2010-08-11T13:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying and removing part of a string of text</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/m-p/62686#M17851</link>
      <description>The SCAN function should do the trick as well:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
name = scan(wholename,1,'(');&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 11 Aug 2010 18:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Identifying-and-removing-part-of-a-string-of-text/m-p/62686#M17851</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-08-11T18:49:12Z</dc:date>
    </item>
  </channel>
</rss>

