<?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: proc sql 'where' filter not being applied inside macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-where-filter-not-being-applied-inside-macro/m-p/737840#M230061</link>
    <description>Thanks, you are correct. The missing '%' and misspelled word came because I had typed the program manually instead of copy-pasting, because I do not have access to copy pasting on the remote machine I am using. &lt;BR /&gt;&lt;BR /&gt;Thanks, for pointing out that there should be no problem with the 'where-clause', I will look else where for the problem then &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 29 Apr 2021 10:34:03 GMT</pubDate>
    <dc:creator>rasmuslarsen</dc:creator>
    <dc:date>2021-04-29T10:34:03Z</dc:date>
    <item>
      <title>proc sql 'where' filter not being applied inside macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-where-filter-not-being-applied-inside-macro/m-p/737830#M230056</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dear everyone&lt;/P&gt;
&lt;P&gt;The following macro mostly works:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It extracts the tables defined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, the "where" clause in the "proc sql" does not have any effect. So the problem is that rows are extracted which do not comply with the "where" clause.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example rows are returned which have ATC = "A0".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do anyone have any ideas what I am doing wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(I have highlighted the part of the code which does seem to have the desired effect, i.e. it does not ensure that only the described ATC-codes are included)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;proc sql;
select memname into :LMDB_names separated by ''
    from dictionary.tables where libname = "RAWDST"
        and memname like "LMDB%"
;quit;      
%let LMDB_len = &amp;amp;sqlobs;
%let LMDB_vars = pnr atc eksd;
     
%macro extract_LMDB(table_list, list_len, col_names);   
        %do i=1 %to &amp;amp;list_len;
        data out.%scan(&amp;amp;table_list, &amp;amp;i);
        merge out.pop (in=in_pop) pdb.%scan(&amp;amp;table_list, &amp;amp;i) (in = in_lmdb);
        by pnr;
        if in_pop = 1 &amp;amp; in_LMDB = 1;
        keep &amp;amp;col_names;
        run;     
        
        proc sql;
        create table out.%scan(&amp;amp;table_list, &amp;amp;i) as        
        select distinct
        pnr, atc,  eksd
        from out.%scan(&amp;amp;table_list, &amp;amp;i)&lt;/FONT&gt;
        
        &lt;STRONG&gt;where      
        upper(atc) like "G%" or
        upper(atc) like "D06%" or
        upper(atc) like "H02AB%" or
        upper(atc) like "G03%" or
        upper(atc) like "L04%"&lt;/STRONG&gt;    
       &lt;FONT size="1 2 3 4 5 6 7"&gt; ;quit;
        %end; 
        %mend extract_LMDB;
        
        &lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 10:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-where-filter-not-being-applied-inside-macro/m-p/737830#M230056</guid>
      <dc:creator>rasmuslarsen</dc:creator>
      <dc:date>2021-04-29T10:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql 'where' filter not being applied inside macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-where-filter-not-being-applied-inside-macro/m-p/737834#M230057</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/56750"&gt;@rasmuslarsen&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/56750"&gt;@rasmuslarsen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The following macro mostly works:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(...)&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;%macro extract_LMDB(table_lidt, list_len, col_names);   
        %do i=1 to &amp;amp;list_len;
...
&lt;/FONT&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't believe that this macro even &lt;EM&gt;compiles&lt;/EM&gt;. Whenever I forget the percent sign in the "&lt;FONT face="courier new,courier"&gt;%to&lt;/FONT&gt;" keyword (and this is my most frequent typo when writing macro code) I obtain the error messages&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#FF0000"&gt;ERROR: Expected %TO not found in %DO statement.
ERROR: A dummy macro will be compiled.&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Moreover, there seems to be a typo&amp;nbsp;&lt;FONT face="courier new,courier"&gt;table_li&lt;FONT color="#FF0000"&gt;d&lt;/FONT&gt;t&lt;/FONT&gt; in the first macro parameter (given that &lt;FONT face="courier new,courier"&gt;&amp;amp;table_li&lt;STRONG&gt;s&lt;/STRONG&gt;t&lt;/FONT&gt; is used in the macro).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So maybe the non-compliant ATC values are from an earlier version of your code. The syntax in your WHERE clause should not cause any problem.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 10:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-where-filter-not-being-applied-inside-macro/m-p/737834#M230057</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-04-29T10:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql 'where' filter not being applied inside macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-where-filter-not-being-applied-inside-macro/m-p/737840#M230061</link>
      <description>Thanks, you are correct. The missing '%' and misspelled word came because I had typed the program manually instead of copy-pasting, because I do not have access to copy pasting on the remote machine I am using. &lt;BR /&gt;&lt;BR /&gt;Thanks, for pointing out that there should be no problem with the 'where-clause', I will look else where for the problem then &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 29 Apr 2021 10:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-where-filter-not-being-applied-inside-macro/m-p/737840#M230061</guid>
      <dc:creator>rasmuslarsen</dc:creator>
      <dc:date>2021-04-29T10:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql 'where' filter not being applied inside macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-where-filter-not-being-applied-inside-macro/m-p/737850#M230067</link>
      <description>&lt;P&gt;Run a PROC FREQ on atc to get a comprehensive list of values there. It might be that you only have values that match at least one of the conditions in the WHERE.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 10:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-where-filter-not-being-applied-inside-macro/m-p/737850#M230067</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-29T10:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql 'where' filter not being applied inside macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-where-filter-not-being-applied-inside-macro/m-p/737937#M230102</link>
      <description>&lt;P&gt;Minor bit of comment but "Like "G%"&amp;nbsp; "&amp;nbsp;&amp;nbsp; will also return the values from "Like "G03%" ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 15:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-where-filter-not-being-applied-inside-macro/m-p/737937#M230102</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-29T15:03:02Z</dc:date>
    </item>
  </channel>
</rss>

