<?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 LOOP a values in a LIKE statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/LOOP-a-values-in-a-LIKE-statement/m-p/689563#M209641</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a file having 6 company names and I want to loop through the names with like to return values from another file (phone number, email, etc). The first problem is I have to loop through the file to get the company names; they are entered kind of manually in the macro now.&lt;/P&gt;&lt;P&gt;The second problem is the syntax in the where statement.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro Rollthecomp;&lt;BR /&gt;%let condition1=GYSERVICESINC;&lt;BR /&gt;%let condition2=MECH;&lt;BR /&gt;%let condition3=ALCOOP;&lt;BR /&gt;%let condition5=RTAGESYSTEMS;&lt;BR /&gt;%let condition4=SCHEMICALS;&lt;BR /&gt;%let condition6=IORPROPANE;&lt;/P&gt;&lt;P&gt;%do i =1 %to 6;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table listcarriers&amp;amp;&amp;amp;i as select phonenumber, email&lt;BR /&gt;from mycompanyfile&lt;BR /&gt;where compress(uniquename) like "&amp;amp;&amp;amp;condition&amp;amp;&amp;amp;i%";&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Oct 2020 14:27:57 GMT</pubDate>
    <dc:creator>Noomen</dc:creator>
    <dc:date>2020-10-07T14:27:57Z</dc:date>
    <item>
      <title>LOOP a values in a LIKE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOP-a-values-in-a-LIKE-statement/m-p/689563#M209641</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a file having 6 company names and I want to loop through the names with like to return values from another file (phone number, email, etc). The first problem is I have to loop through the file to get the company names; they are entered kind of manually in the macro now.&lt;/P&gt;&lt;P&gt;The second problem is the syntax in the where statement.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro Rollthecomp;&lt;BR /&gt;%let condition1=GYSERVICESINC;&lt;BR /&gt;%let condition2=MECH;&lt;BR /&gt;%let condition3=ALCOOP;&lt;BR /&gt;%let condition5=RTAGESYSTEMS;&lt;BR /&gt;%let condition4=SCHEMICALS;&lt;BR /&gt;%let condition6=IORPROPANE;&lt;/P&gt;&lt;P&gt;%do i =1 %to 6;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table listcarriers&amp;amp;&amp;amp;i as select phonenumber, email&lt;BR /&gt;from mycompanyfile&lt;BR /&gt;where compress(uniquename) like "&amp;amp;&amp;amp;condition&amp;amp;&amp;amp;i%";&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 14:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOP-a-values-in-a-LIKE-statement/m-p/689563#M209641</guid>
      <dc:creator>Noomen</dc:creator>
      <dc:date>2020-10-07T14:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP a values in a LIKE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOP-a-values-in-a-LIKE-statement/m-p/689570#M209644</link>
      <description>&lt;P&gt;It's not completely clear what you are doing, but you don't have loop through a file to get company names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select distinct companynames into :names separated by '~' from yourdataset;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This creates a macro variable called &amp;amp;NAMES with all of the unique company names in it, separated by a tilde (~)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, do the looping like this (naturally, this is untested code)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis;
    proc sql;
        create table carriers as select phonenumber, email
        from mycompanyfile
        where (
        %do i=1 %to %sysfunc(countw,&amp;amp;names,~);
            compress(uniquename) like "%scan(&amp;amp;names,&amp;amp;i,~)"
            %if &amp;amp;i&amp;lt;%sysfunc(countw,&amp;amp;names,~) %then or;
         %end;
         );
    quit;
%mend;
%dothis&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This creates one large file with all of the companies found, rather than many smaller files for each company. I strongly recommend you handle it via one large file and then use BY statements or WHERE clauses when you want to analyze the individual companies.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 14:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOP-a-values-in-a-LIKE-statement/m-p/689570#M209644</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-07T14:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP a values in a LIKE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOP-a-values-in-a-LIKE-statement/m-p/689575#M209646</link>
      <description>&lt;P&gt;Why did you double the &amp;amp;'s?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where compress(uniquename) like "&amp;amp;&amp;amp;condition&amp;amp;&amp;amp;i%"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When the macro processor sees two &amp;amp;'s it will convert that to one and then re-scan for macro variable references.&amp;nbsp; So this will be evaluate the &amp;amp;&amp;amp;&amp;nbsp; to&amp;nbsp; &amp;amp; which will result in &amp;amp;condition&amp;amp;i which look for the value of a macro variable named CONDITION and then append the value of I to the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where compress(uniquename) like "&amp;amp;&amp;amp;condition&amp;amp;i%"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will evaluated in this order.&amp;nbsp; &amp;amp;&amp;amp; -&amp;gt; &amp;amp;&amp;nbsp; and &amp;amp;i -&amp;gt; 1.&amp;nbsp; Which will result in &amp;amp;condition1 which will then be evaluated.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 15:22:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOP-a-values-in-a-LIKE-statement/m-p/689575#M209646</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-07T15:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP a values in a LIKE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LOOP-a-values-in-a-LIKE-statement/m-p/690081#M209869</link>
      <description>&lt;P&gt;Thank you for the syntax for the sysfunc is&lt;/P&gt;&lt;P&gt;%do i=1 %to %sysfunc(countw(&amp;amp;names,~));&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2020 16:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LOOP-a-values-in-a-LIKE-statement/m-p/690081#M209869</guid>
      <dc:creator>Noomen</dc:creator>
      <dc:date>2020-10-08T16:13:49Z</dc:date>
    </item>
  </channel>
</rss>

