<?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: Removing string from another string in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56959#M327</link>
    <description>Did you look at the DOC and possibly using the TRANWRD function in a DATA step, as suggested?  The function can be used with SAS variables as well as constants.  Here's a Google advanced search argument to help you find related topic info on the SAS support   &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website:&lt;BR /&gt;
&lt;BR /&gt;
tranwrd function site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Thu, 23 Jul 2009 12:43:36 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-07-23T12:43:36Z</dc:date>
    <item>
      <title>Removing string from another string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56953#M321</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I have two variable whose values are strings,&lt;BR /&gt;
I want to remove substring from big string.&lt;BR /&gt;
for example,&lt;BR /&gt;
&lt;BR /&gt;
A=adc sgk ghhj &lt;BR /&gt;
B= sgk&lt;BR /&gt;
&lt;BR /&gt;
I want to create a new variable as C, So that  it should be c=adc ghhj.&lt;BR /&gt;
Can any one give the solution on that?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance,&lt;BR /&gt;
Pabitra</description>
      <pubDate>Tue, 21 Jul 2009 12:16:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56953#M321</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-21T12:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Removing string from another string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56954#M322</link>
      <description>Explore the use of SAS function TRANWRD to assign a new SAS variable.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 21 Jul 2009 13:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56954#M322</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-21T13:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Removing string from another string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56955#M323</link>
      <description>&amp;gt; Hi,&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I have two variable whose values are strings,&lt;BR /&gt;
&amp;gt; I want to remove substring from big string.&lt;BR /&gt;
&amp;gt; for example,&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; A=adc sgk ghhj &lt;BR /&gt;
&amp;gt; B= sgk&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I want to create a new variable as C, So that  it&lt;BR /&gt;
&amp;gt; should be c=adc ghhj.&lt;BR /&gt;
&amp;gt; Can any one give the solution on that?&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Thanks in advance,&lt;BR /&gt;
&amp;gt; Pabitra&lt;BR /&gt;
&lt;BR /&gt;
Hi Pabitra,&lt;BR /&gt;
&lt;BR /&gt;
One way to accomplish this is to use the BASE SAS substring function in an EM SAS code node.  &lt;BR /&gt;
&lt;BR /&gt;
Substr Returns a portion of the variable value based on a starting position&lt;BR /&gt;
and number of characters.&lt;BR /&gt;
&lt;BR /&gt;
cpart1 = SUBSTR(a,1,3);&lt;BR /&gt;
cpart2 =SUBSTR(a,9,3);&lt;BR /&gt;
&lt;BR /&gt;
You could runt the function twice as above  and the use || to cancatenate back the two extract strings into a single varaible c =adc ghhj. &lt;BR /&gt;
&lt;BR /&gt;
c=cpart1 ||(left)cpart2;&lt;BR /&gt;
drop cpart1 cpart2;&lt;BR /&gt;
Others may have an easier step.</description>
      <pubDate>Tue, 21 Jul 2009 13:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56955#M323</guid>
      <dc:creator>WayneThompson</dc:creator>
      <dc:date>2009-07-21T13:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: Removing string from another string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56956#M324</link>
      <description>You may also be interested by the Regular Expressions. &lt;BR /&gt;
I do not know how to handle them in SAS specifically. &lt;BR /&gt;
But it is a very powerfull way to detect string within string, test them, and handle them.</description>
      <pubDate>Wed, 22 Jul 2009 12:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56956#M324</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-22T12:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Removing string from another string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56957#M325</link>
      <description>Base SAS code is always fun.  What if you don't know the length of the strings but you do know that space is the separator and that you want the first chunk from A and the third chunk from B.  Use the scan function.&lt;BR /&gt;
&lt;BR /&gt;
length c $32 ;&lt;BR /&gt;
c= scan(a,1,' ') !! ' ' !! scan(b,3,' ');&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Now, what if you don't know how many chunks there are in B, but you know you want the last?  Use the reverse function.&lt;BR /&gt;
&lt;BR /&gt;
length c $32 ;&lt;BR /&gt;
c= scan(a,1,' ') !! ' ' !! reverse(scan(reverse(b),1,' '));&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
When using EM 5.3 or 6.1, you can enter the expression directly into the SCORE code editor in the CODE node or the TRANSFORM Node.  You do not need to enter DATA, SET, or RUN statements.  The code will be inserted into the diagram's score code.  &lt;BR /&gt;
&lt;BR /&gt;
What if you want to use the variable C in a model but you want to reject A and B?  You can do this in your CODE node as well.  The CODE node has editors for TRAIN, SCORE, and REPORT code.  Enter this code into the TRAIN code.&lt;BR /&gt;
&lt;BR /&gt;
%EM_METACHANGE(name=A, role=rejected) ;&lt;BR /&gt;
%EM_METACHANGE(name=B, role=rejected) ; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The new variable C will have the role of input by default.  If you want to set that explicitly, you can do this:&lt;BR /&gt;
&lt;BR /&gt;
%EM_METACHANGE(name=C, role=input, level=nominal) ;&lt;BR /&gt;
&lt;BR /&gt;
You do NOT want to drop A and B from the data since that will cause the score code to fail when the expression that creates C is evaluated after a temporary data set has been created.  &lt;BR /&gt;
&lt;BR /&gt;
In general, EM does not drop variables from the data set, and does not change the values of existing variables.  &lt;BR /&gt;
&lt;BR /&gt;
cheers.</description>
      <pubDate>Wed, 22 Jul 2009 12:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56957#M325</guid>
      <dc:creator>David_Duling</dc:creator>
      <dc:date>2009-07-22T12:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Removing string from another string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56958#M326</link>
      <description>Thanks for the ans....&lt;BR /&gt;
But i need it for general...i mean i want to apply for two columns whose values are the strings...&lt;BR /&gt;
&lt;BR /&gt;
can some one give me any suggestion...&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance......&lt;BR /&gt;
&lt;BR /&gt;
pabitra</description>
      <pubDate>Thu, 23 Jul 2009 09:28:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56958#M326</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-23T09:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Removing string from another string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56959#M327</link>
      <description>Did you look at the DOC and possibly using the TRANWRD function in a DATA step, as suggested?  The function can be used with SAS variables as well as constants.  Here's a Google advanced search argument to help you find related topic info on the SAS support   &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website:&lt;BR /&gt;
&lt;BR /&gt;
tranwrd function site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 23 Jul 2009 12:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56959#M327</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-23T12:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Removing string from another string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56960#M328</link>
      <description>ok, how about this - you can use the string that should be removed as the delimiter in the scan function.  Works both with and without spaces.&lt;BR /&gt;
&lt;BR /&gt;
data _null_ ;&lt;BR /&gt;
a= 'asdf yyy sdfs' ;&lt;BR /&gt;
b= 'yyy' ;&lt;BR /&gt;
c= scan(a,1,b) !! ' ' !! scan(a,2,b) ;&lt;BR /&gt;
put c ; &lt;BR /&gt;
run ;</description>
      <pubDate>Thu, 23 Jul 2009 18:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56960#M328</guid>
      <dc:creator>David_Duling</dc:creator>
      <dc:date>2009-07-23T18:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Removing string from another string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56961#M329</link>
      <description>Honestly, is there some aversion with using a function for its defined purpose, or am I missing something with this elongated thread?&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 23 Jul 2009 19:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56961#M329</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-23T19:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Removing string from another string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56962#M330</link>
      <description>For simply removing one string form another, that is the way to go.  &lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;TRANWRD&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000215027.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000215027.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
rc= tranwrd(a,b,' ');</description>
      <pubDate>Thu, 23 Jul 2009 20:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56962#M330</guid>
      <dc:creator>David_Duling</dc:creator>
      <dc:date>2009-07-23T20:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Removing string from another string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56963#M331</link>
      <description>new_string= compress(tranwrd(original_string, trim(unwanted_string),'01'x ), x'01' ); &lt;BR /&gt;
&lt;BR /&gt;
thus ensuring all occurrences of what is in "unwanted_string" are removed, without leaving a blank for each occurrence.&lt;BR /&gt;
The trim() function is used to ensure those cases not fully using the width of the variable named unwanted_string will match only on the non-blank (left-hand) part.&lt;BR /&gt;
The compress() function will remove the substitutions for the unwanted_string.</description>
      <pubDate>Mon, 03 Aug 2009 14:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56963#M331</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-08-03T14:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Removing string from another string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56964#M332</link>
      <description>data _null_;&lt;BR /&gt;
    a='abc def kkk xyz kkk qwe';&lt;BR /&gt;
    b='kkk';&lt;BR /&gt;
    c=prxchange('s/'||b||'//', -1, a);&lt;BR /&gt;
    put a= b= c=;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
will get you this:  a=abc def kkk xyz kkk qwe b=kkk c=abc def  xyz  qwe&lt;BR /&gt;
&lt;BR /&gt;
Note that it doesn't deal with the resultant two-blank. And it will replace portions of a word containing kkk.  With suitable changes to the regular expression, you can deal with all of those situations.</description>
      <pubDate>Thu, 13 Aug 2009 14:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Removing-string-from-another-string/m-p/56964#M332</guid>
      <dc:creator>DLing</dc:creator>
      <dc:date>2009-08-13T14:08:12Z</dc:date>
    </item>
  </channel>
</rss>

