<?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: Simplify the coding - Macro? Do Loop? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687649#M208773</link>
    <description>&lt;P&gt;Can there be many matches for the same string?&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 19:43:05 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2020-09-29T19:43:05Z</dc:date>
    <item>
      <title>Simplify the coding - Macro? Do Loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687572#M208742</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to simplify the codes below.&amp;nbsp; I have around 15 lines of Prxmatch.&amp;nbsp;&amp;nbsp; I list a few of them below, thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
    if prxmatch('/uairway/i',uothersp) then uairway=1; 
	if prxmatch('/uapnea/i',uothersp) then uapnea=1;
	if prxmatch('/ugastro/i',uothersp) then ugastro=1;
	if prxmatch('/ugerd/i',uothersp) then ugerd=1;
	if prxmatch('/uendo/i',uothersp) then uendo=1;
	if prxmatch('/uallergy/i',uothersp) then uallergy=1;
	if prxmatch('/uprem/i',uothersp) then uprem=1;
	if prxmatch('/ugestage/i',uothersp) then ugestage=1;

run;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687572#M208742</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-09-29T16:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the coding - Macro? Do Loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687576#M208745</link>
      <description>Have you tried an array?</description>
      <pubDate>Tue, 29 Sep 2020 16:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687576#M208745</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-29T16:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the coding - Macro? Do Loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687649#M208773</link>
      <description>&lt;P&gt;Can there be many matches for the same string?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:43:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687649#M208773</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-09-29T19:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the coding - Macro? Do Loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687706#M208802</link>
      <description>&lt;P&gt;Not a simplification (I don't think you can in a meaningful way), but a performance improvement: The find() function is a lot less expensive than the prxmatch() function.&lt;/P&gt;
&lt;P&gt;Also this syntax might be slightly more compact:&lt;/P&gt;
&lt;PRE&gt;UAIRWAY = find(UOTHERSP, 'uairway', 'i') &amp;gt; 0 ; &lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687706#M208802</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-30T01:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the coding - Macro? Do Loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687707#M208803</link>
      <description>&lt;P&gt;If you really want to remove the tests, you can do something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let strings=UAIRWAY UGASTRO;
%macro loop;
&amp;nbsp;&amp;nbsp;%local i;
&amp;nbsp; %do i=1 %to %sysfunc(countw(&amp;amp;strings));
    %scan(&amp;amp;strings,&amp;amp;i) = find(UOTHERSP, "%scan(&amp;amp;strings,&amp;amp;i)", 'i') &amp;gt; 0 ; 
  %end;
%mend;
%loop;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You removed 15-8=7 lines of code, but it's a lot less legible now. Not worth it imho.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:57:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687707#M208803</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-30T03:57:15Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the coding - Macro? Do Loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687754#M208829</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; advice of using arrays :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
	array vars uairway uapnea ugastro ugerd uendo uallergy uprem ugestage;

    do over vars;
        if find(uothersp,vname(vars),"i") then vars=1;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 09:22:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687754#M208829</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2020-09-30T09:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the coding - Macro? Do Loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687923#M208894</link>
      <description>&lt;P&gt;Thank you so much, ChrisNZ and Gamotte.&amp;nbsp;&amp;nbsp; Both programs work!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 18:31:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-coding-Macro-Do-Loop/m-p/687923#M208894</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-09-30T18:31:12Z</dc:date>
    </item>
  </channel>
</rss>

