<?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: Exchange a text fragment by designing rule? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/725454#M225344</link>
    <description>Hello PG,&lt;BR /&gt;&lt;BR /&gt;Thank you so much for the thoroughly coding.   But why adding spacing after commas?  I removed the space, and didn't find any difference between the result.</description>
    <pubDate>Thu, 11 Mar 2021 14:34:46 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2021-03-11T14:34:46Z</dc:date>
    <item>
      <title>Exchange a text fragment by designing rule?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/724959#M225106</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a sample dataset "Have."&amp;nbsp;&amp;nbsp;&amp;nbsp; I would like to have replace&amp;nbsp;the text fragments&amp;nbsp;with some specific rules as following:&lt;/P&gt;
&lt;P&gt;1. If the text contain ' CLEFT PALETTE / CLEFT LIP ' fragments, replace with 'AIRWAY.'&lt;/P&gt;
&lt;P&gt;2. If the text contain ' ADHD / AUTISM / SPEECH &amp;amp; COGNITIVE DELAY' fragments, replace with 'DEVDIS.'&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;3. If the text contain 'GTUBE' fragments, replace with 'GASTRO&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;.'&lt;/P&gt;
&lt;P&gt;4. If the text contain 'ENCEPHALO' fragments, replace with 'NEURO.'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The final result I would like to get is shown in the 'Want' dataset.&amp;nbsp; I think it might be used Prxchange, not sure how.&amp;nbsp;&amp;nbsp; If there are any other ways, I am happy to try it as long as it works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data Have;
      infile datalines delimiter='/';
  input Disease : $300.  ;
datalines;
	CLEFT PALETTE, ADHD, CHRONIC RHINITIS /
	HAVING A GTUBE, ENCEPHALOMALACIA, HIDRADENITIS, AUTISM/
	ENCEPHALOPATHY, GTUBE SUPPORTIVE, HEP C EXPOSURE /
	AUTISM SPECTRUM, SPEECH &amp;amp; COGNITIVE DELAY, CLEFT LIP
;
run;

data Want;
      infile datalines delimiter='/';
  input Disease : $300.  ;
datalines;
	AIRWAY, DEVDIS, CHRONIC RHINITIS /
	GASTRO, NEURO, OTHER, DEVDIS /
	NEURO, GASTRO, HEP C EXPOSURE /
	DEVDIS, DEVDIS, AIRWAY
;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 19:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/724959#M225106</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2021-03-09T19:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: Exchange a text fragment by designing rule?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/725276#M225243</link>
      <description>&lt;P&gt;Something like this should work (sorry can't test atm):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  DISEASE=prxchange('s/[^,]*(CLEFT PALETTE|CLEFT LIP)[^,]*/AIRWAY/i',-1,DISEASE);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 21:49:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/725276#M225243</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-10T21:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: Exchange a text fragment by designing rule?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/725301#M225251</link>
      <description>&lt;P&gt;Testing &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; 's suggestion:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
      infile datalines delimiter='/';
  input Disease : $300.  ;
datalines;
    CLEFT PALETTE, ADHD, CHRONIC RHINITIS /
    HAVING A GTUBE, ENCEPHALOMALACIA, HIDRADENITIS, AUTISM/
    ENCEPHALOPATHY, GTUBE SUPPORTIVE, HEP C EXPOSURE /
    AUTISM SPECTRUM, SPEECH &amp;amp; COGNITIVE DELAY, CLEFT LIP
;

data want;
set have;
Disease2 = prxchange('s/[^,]*(CLEFT PALETTE|CLEFT LIP)[^,]*/AIRWAY/i',              -1, Disease);
Disease3 = prxchange('s/[^,]*(ADHD|AUTISM|SPEECH &amp;amp; COGNITIVE DELAY)[^,]*/DEVDIS/i', -1, Disease2);
Disease4 = prxchange('s/[^,]*(GTUBE)[^,]*/GASTRO/i',                                -1, Disease3);
Disease5 = prxchange('s/[^,]*(ENCEPHALO)[^,]*/NEURO/i',                             -1, Disease4);
Disease6 = prxchange('s/[^,]*(HIDRADENITIS)[^,]*/OTHER/i',                          -1, Disease5);
/* Add spaces after commas */
Disease7 = prxchange('s/,(\w)/, \1/',                          -1, Disease6);
Disease_transformed = Disease7;
keep Disease Disease_transformed;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_1-1615419435243.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55799i1C6170BE326D417D/image-size/large?v=v2&amp;amp;px=999" role="button" title="PGStats_1-1615419435243.png" alt="PGStats_1-1615419435243.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;He's right!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 23:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/725301#M225251</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-03-10T23:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Exchange a text fragment by designing rule?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/725454#M225344</link>
      <description>Hello PG,&lt;BR /&gt;&lt;BR /&gt;Thank you so much for the thoroughly coding.   But why adding spacing after commas?  I removed the space, and didn't find any difference between the result.</description>
      <pubDate>Thu, 11 Mar 2021 14:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/725454#M225344</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2021-03-11T14:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: Exchange a text fragment by designing rule?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/725538#M225383</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&amp;nbsp;But why adding spacing after commas? &lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Simply because you had spaces after the commas in your example above.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 17:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/725538#M225383</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-03-11T17:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: Exchange a text fragment by designing rule?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/725648#M225436</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;why adding spacing after commas&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;To make the code more legible. A very good habit indeed. Like using the case to mean something (like lower case for language keywords, and uppercase for user names such as variable names).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 22:11:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/725648#M225436</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-11T22:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: Exchange a text fragment by designing rule?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/725693#M225460</link>
      <description>&lt;P&gt;Thanks, Chris and PG made a great effort to help me out.&amp;nbsp; Because Chris is the first one giving me the idea, I accepted his answer as the solution, although PG showed a more complete program and the details. Sometimes, it's hard to decide which is the best solution. I wish I could credit both of your valuable work.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 02:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exchange-a-text-fragment-by-designing-rule/m-p/725693#M225460</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2021-03-12T02:01:30Z</dc:date>
    </item>
  </channel>
</rss>

