<?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: Problem with macro loops in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-macro-loops/m-p/946975#M42518</link>
    <description>Thank you! This worked.</description>
    <pubDate>Thu, 10 Oct 2024 13:32:53 GMT</pubDate>
    <dc:creator>Stanley3</dc:creator>
    <dc:date>2024-10-10T13:32:53Z</dc:date>
    <item>
      <title>Problem with macro loops</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-macro-loops/m-p/946894#M42514</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm new at macro writing and trying out what I thought should be an easy one. The purpose of the macro is to check that the categorical variables I created from continuous variables are set correctly. This is my code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro check(data=, Cat=, Cont=);
    %let total_cat_vars = %sysfunc(countw(&amp;amp;Cat));
    %let total_cont_vars = %sysfunc(countw(&amp;amp;Cont));
    
    %do i = 1 %to &amp;amp;total_cat_vars;
        %let selected_cat_var = %scan(&amp;amp;Cat, &amp;amp;i);

        proc sort data=&amp;amp;data;
            by &amp;amp;selected_cat_var;
        run;

        %do j = 1 %to &amp;amp;total_cont_vars;
            %let selected_cont_var = %scan(&amp;amp;Cont, &amp;amp;j);

            proc means data=&amp;amp;data n nmiss min max mean median q1 q3;
                var &amp;amp;selected_cont_var;
                by &amp;amp;selected_cat_var;
            run;

        %end; 

    %end; 
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem is that it is running proc means for all of my continuous variables by each of my categorical variables (ie. I want only peso_nac to be ran with low_bw, but not sdg_nac). This can be seen here in the log with the mprint option:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-10-09 at 11.29.19 PM.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101074i0E7D3594CA4549FE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-10-09 at 11.29.19 PM.png" alt="Screenshot 2024-10-09 at 11.29.19 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I am not sure how to modify this macro to fix this. Any input is appreciated, thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 03:33:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-macro-loops/m-p/946894#M42514</guid>
      <dc:creator>Stanley3</dc:creator>
      <dc:date>2024-10-10T03:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with macro loops</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-macro-loops/m-p/946896#M42515</link>
      <description>&lt;P&gt;Please show the code you used to actually CALL the macro.&lt;/P&gt;
&lt;P&gt;Please show the SAS code you want it to produce for that call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you even need a macro to do what you want?&lt;/P&gt;
&lt;P&gt;Couldn't you just do it all with one PROC MEANS call?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=&amp;amp;data n nmiss min max mean median q1 q3;
  ways 1;
  class &amp;amp;cat;
  var &amp;amp;cont ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Oct 2024 03:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-macro-loops/m-p/946896#M42515</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-10T03:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with macro loops</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-macro-loops/m-p/946931#M42517</link>
      <description>&lt;P&gt;Agreeing with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use one call to PROC MEANS for each data set.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 10:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-macro-loops/m-p/946931#M42517</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-10T10:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with macro loops</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-macro-loops/m-p/946975#M42518</link>
      <description>Thank you! This worked.</description>
      <pubDate>Thu, 10 Oct 2024 13:32:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-macro-loops/m-p/946975#M42518</guid>
      <dc:creator>Stanley3</dc:creator>
      <dc:date>2024-10-10T13:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with macro loops</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-macro-loops/m-p/946976#M42519</link>
      <description>Thank you!</description>
      <pubDate>Thu, 10 Oct 2024 13:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-macro-loops/m-p/946976#M42519</guid>
      <dc:creator>Stanley3</dc:creator>
      <dc:date>2024-10-10T13:33:07Z</dc:date>
    </item>
  </channel>
</rss>

