<?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: Macro Loop with Array Value in Where Statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406129#M98837</link>
    <description>&lt;LI-CODE lang="sas"&gt;           proc freq data =  risk.rapsPending_s2a (where = (RARCASE_CCO_CODE_2 in ( "ZCH" "ZHN") )  order = freq;

                by RARCASE_CCO_CODE_2;

                format RARAPPL_CNTRY_OF_BIRTH_CODE $cntry.;
                tables RARAPPL_CNTRY_OF_BIRTH_CODE / missing;
                title "Country of Birth";
           run;&lt;/LI-CODE&gt;
&lt;P&gt;Is there a specific reason to not use BY groups here? It seems like it would be more efficient and less code....&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Oct 2017 20:09:00 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-10-20T20:09:00Z</dc:date>
    <item>
      <title>Macro Loop with Array Value in Where Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406115#M98832</link>
      <description>&lt;P&gt;Hi, All.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to streamline my code to use a single frequency procedure code bloc one inside a loop of 8 iterations. But as always with the macros, it is something that should work, but there is something about the&amp;nbsp;chewed bubblegum, duct-taped, cotton-plugged wiring of&amp;nbsp;the way SAS manages macros that is not working. The following code is based off a similar routine that I wrote that used macro variable in the IF statement -and worked- but does not here. I have tried multiple ways of specifying the values in the array, as well as worked with the ampersands and quotes to no avail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let officeCodes = array officeCodes[8] $3 code1-code8 (ZAR ZCH ZHN ZLA ZMI ZNK ZNY ZSF);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; count(toomany);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i = &lt;STRONG&gt;1&lt;/STRONG&gt; %to &amp;amp;toomany;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc freq data =&amp;nbsp; risk.rapsPending_s2a (where = (RARCASE_CCO_CODE_2 =&amp;nbsp; "&amp;amp;&amp;amp;officeCodes[&amp;amp;i.]")) order = freq;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format RARAPPL_CNTRY_OF_BIRTH_CODE $cntry.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables RARAPPL_CNTRY_OF_BIRTH_CODE / missing;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; title "Country of Birth";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt; count;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;EM&gt;count&lt;/EM&gt;&lt;/STRONG&gt;(&lt;STRONG&gt;8&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the following message. From everything I know and looked up, it should work.&amp;nbsp; I really hate the way SAS implements macros…. Seems like they just kept gluing cotton on to duct-tape balls that held loose wiring together given the way this software developed.&amp;nbsp; It’s always the macros.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: No observations were selected from data set RISK.RAPSPENDING_S2A.&lt;/P&gt;&lt;P&gt;NOTE: There were 0 observations read from the data set RISK.RAPSPENDING_S2A.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE 0 /* an obviously FALSE WHERE clause */ ;&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE FREQ used (Total process time):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ron&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 19:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406115#M98832</guid>
      <dc:creator>RedMcCallen</dc:creator>
      <dc:date>2017-10-20T19:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop with Array Value in Where Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406116#M98833</link>
      <description>&lt;P&gt;Arrays don't work that way. There's no such thing as a SAS macro array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 19:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406116#M98833</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T19:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop with Array Value in Where Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406120#M98834</link>
      <description>&lt;P&gt;I have used arrays in evaluation statement before that were inside of loops, and they worked. The following worked:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let topMetros = array topMetros[10] $5 metro1-metro10 ("35620" "31080" "33100" "16980" "41860" "47900" "26420" "19100" "41940" "14460");&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;%macro count(toomany);&lt;BR /&gt;%do i = 1 %to &amp;amp;toomany;&lt;BR /&gt;data geog.uscis_ois_lpr_s5_mtr&amp;amp;i. (drop = metro:);&lt;BR /&gt;set geog.uscis_ois_lpr_s5_metros;&lt;BR /&gt;&amp;amp;topMetros;&lt;/P&gt;&lt;P&gt;if CBSA_CODE = topMetros[&amp;amp;i.] then&lt;BR /&gt;output geog.uscis_ois_lpr_s5_mtr&amp;amp;i.;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%mend count;&lt;BR /&gt;%count(10);&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 19:58:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406120#M98834</guid>
      <dc:creator>RedMcCallen</dc:creator>
      <dc:date>2017-10-20T19:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop with Array Value in Where Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406123#M98835</link>
      <description>&lt;P&gt;Yes, because that's fully valid SAS syntax. Your current one is not, the code generated needs to be valid SAS code. This is not. Do a text replacement and you'll see that there's several invalid SAS syntax issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Arrays are valid only in data steps, but not in PROC FREQ for sure.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406123#M98835</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T20:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop with Array Value in Where Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406124#M98836</link>
      <description>&lt;P&gt;Untested code, you should add a check to verify that &amp;amp;i is not higher than %sysfunc(countw(&amp;amp;officeCodes))&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let officeCodes = ZAR ZCH ZHN ZLA ZMI ZNK ZNY ZSF;
 
%macro count(toomany);
     %do i = 1 %to &amp;amp;toomany;
           proc freq data =  risk.rapsPending_s2a (where = (RARCASE_CCO_CODE_2 =  "%scan(&amp;amp;officeCodes, &amp;amp;i")) order = freq;
                format RARAPPL_CNTRY_OF_BIRTH_CODE $cntry.;
                tables RARAPPL_CNTRY_OF_BIRTH_CODE / missing;
                title "Country of Birth";
           run;
     %end;
%mend count;
%count(8);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:05:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406124#M98836</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-10-20T20:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop with Array Value in Where Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406129#M98837</link>
      <description>&lt;LI-CODE lang="sas"&gt;           proc freq data =  risk.rapsPending_s2a (where = (RARCASE_CCO_CODE_2 in ( "ZCH" "ZHN") )  order = freq;

                by RARCASE_CCO_CODE_2;

                format RARAPPL_CNTRY_OF_BIRTH_CODE $cntry.;
                tables RARAPPL_CNTRY_OF_BIRTH_CODE / missing;
                title "Country of Birth";
           run;&lt;/LI-CODE&gt;
&lt;P&gt;Is there a specific reason to not use BY groups here? It seems like it would be more efficient and less code....&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406129#M98837</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T20:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop with Array Value in Where Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406130#M98838</link>
      <description>&lt;P&gt;That throws a whole number of errors.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406130#M98838</guid>
      <dc:creator>RedMcCallen</dc:creator>
      <dc:date>2017-10-20T20:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop with Array Value in Where Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406132#M98839</link>
      <description>&lt;P&gt;The intent of the code is to produce a frequency output for each of the&amp;nbsp;eight offices. I don't want to write eight Proc Freq code blocs for each office,. From the way I read the use of the in function here it is treating it like a single evaluation for any of the eight offices. And if one of the offices evaluates true for the in function, then produce the output.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406132#M98839</guid>
      <dc:creator>RedMcCallen</dc:creator>
      <dc:date>2017-10-20T20:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop with Array Value in Where Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406138#M98842</link>
      <description>&lt;P&gt;That's incorrect, note the addition of the BY statement as well. The BY statement creates a table for each unique value of the BY group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a fully worked example that you can run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=class; by sex; run;

proc freq data=class;
by sex;

table age;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406138#M98842</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T20:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop with Array Value in Where Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406141#M98843</link>
      <description>&lt;P&gt;Ok... I executed this code and I see what it does now. &amp;nbsp;Thank you. I did not realize the BY statement would treat it as separate instances for each element inside the IN function. I like this better because it keeps the code simple and efficient, which is always what I am looking for over elegance and showing off as a number of programmers like to do. I think I still have the problem -a minor one- which is that I wanted the title of each of the eight offices to show up after the Country of Birth title. Not sure I can get that here, but that is a minor issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:23:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406141#M98843</guid>
      <dc:creator>RedMcCallen</dc:creator>
      <dc:date>2017-10-20T20:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop with Array Value in Where Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406142#M98844</link>
      <description>&lt;P&gt;Yup... I see that now. I was just unaware that the BY statement would do that to the IN function. It's these types of things that makes me like SAS so much. It's just the macros that drive me crazy. From years of programming statistical software in a language, macro programming is just something that I can't fit my mind to because it&amp;nbsp;just seem so over-complicated and lacking in functioning well with base code.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406142#M98844</guid>
      <dc:creator>RedMcCallen</dc:creator>
      <dc:date>2017-10-20T20:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop with Array Value in Where Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406145#M98845</link>
      <description>&lt;P&gt;You can control the titles and BY Value titles.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Google #BYVAL and you'll find examples.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406145#M98845</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T20:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop with Array Value in Where Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406147#M98846</link>
      <description>&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi23/Coders/p75.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi23/Coders/p75.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 20:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-with-Array-Value-in-Where-Statement/m-p/406147#M98846</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-20T20:33:21Z</dc:date>
    </item>
  </channel>
</rss>

