<?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 Problem with genmod macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929654#M41728</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am running the following macro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;%macro geomeans (data=, outcome=);

	%let total_vars = %sysfunc (countw (&amp;amp;outcome) );
	%do i = 1 %to &amp;amp;total_vars;
		%let selected_var=%scan (&amp;amp;outcome, &amp;amp;i);

               ods output estimates=geomeans&amp;amp;i; 
			proc genmod data=&amp;amp;data;
				class brinda15 / param = glm;
     			model &amp;amp;outcome = brinda15 / type3 dist=normal ;
						estimate "Overall estimate &amp;amp;outcome brinda15 =0" intercept 1 brinda15 1 0  /exp; 
						estimate "Overall estimate &amp;amp;outcome brinda15 =1 " intercept 1 brinda15 0 1  /exp; 
			run;
		ods output close;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;I call the macro with the following code:&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;%geomeans (data=db, outcome=var1 var2 var3)&lt;/PRE&gt;It works only for the first variable (it doesn't matter which one it is), but for the other variables I the error message below&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-05-24 at 6.32.33 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96762iA5EAEFCC1F04498A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-05-24 at 6.32.33 PM.png" alt="Screenshot 2024-05-24 at 6.32.33 PM.png" /&gt;&lt;/span&gt; &lt;/DIV&gt;&lt;DIV&gt;In case it matters, my outcomes are continuous and ln transformed.&lt;/DIV&gt;&lt;DIV&gt;Any tips of how to fix this are welcome!&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 May 2024 22:34:14 GMT</pubDate>
    <dc:creator>Stanley3</dc:creator>
    <dc:date>2024-05-24T22:34:14Z</dc:date>
    <item>
      <title>Problem with genmod macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929654#M41728</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am running the following macro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;%macro geomeans (data=, outcome=);

	%let total_vars = %sysfunc (countw (&amp;amp;outcome) );
	%do i = 1 %to &amp;amp;total_vars;
		%let selected_var=%scan (&amp;amp;outcome, &amp;amp;i);

               ods output estimates=geomeans&amp;amp;i; 
			proc genmod data=&amp;amp;data;
				class brinda15 / param = glm;
     			model &amp;amp;outcome = brinda15 / type3 dist=normal ;
						estimate "Overall estimate &amp;amp;outcome brinda15 =0" intercept 1 brinda15 1 0  /exp; 
						estimate "Overall estimate &amp;amp;outcome brinda15 =1 " intercept 1 brinda15 0 1  /exp; 
			run;
		ods output close;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;I call the macro with the following code:&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;%geomeans (data=db, outcome=var1 var2 var3)&lt;/PRE&gt;It works only for the first variable (it doesn't matter which one it is), but for the other variables I the error message below&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-05-24 at 6.32.33 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96762iA5EAEFCC1F04498A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-05-24 at 6.32.33 PM.png" alt="Screenshot 2024-05-24 at 6.32.33 PM.png" /&gt;&lt;/span&gt; &lt;/DIV&gt;&lt;DIV&gt;In case it matters, my outcomes are continuous and ln transformed.&lt;/DIV&gt;&lt;DIV&gt;Any tips of how to fix this are welcome!&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 22:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929654#M41728</guid>
      <dc:creator>Stanley3</dc:creator>
      <dc:date>2024-05-24T22:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with genmod macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929655#M41729</link>
      <description>&lt;P&gt;Based on extensive macro language experience, but zero genmod experience:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is unusual to create the macro variable &amp;amp;SELECTED_VAR but then never use it.&amp;nbsp; Is it possible that your MODEL statement is supposed to refer to &amp;amp;SELECTED_VAR, not &amp;amp;OUTCOME?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The same could easily apply to the ESTIMATE statements as well (although that appears to be a label and wouldn't cause an error, just a labeling issue).,&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2024 23:17:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929655#M41729</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-05-24T23:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with genmod macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929664#M41736</link>
      <description>&lt;P&gt;Since your macro code is incomplete (missing and %end; and %mend; at the very least) we can't test your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Set&lt;/P&gt;
&lt;PRE&gt;options mprint;&lt;/PRE&gt;
&lt;P&gt;before running the macro. The LOG will show much more detail of the generated code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Agree you have the wrong variable on the model statement.&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2024 04:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929664#M41736</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-25T04:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with genmod macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929676#M41737</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;&amp;nbsp;already gave the correct answer.&amp;nbsp; This is a nice example of why&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;'s point of turning on the MPRINT option is critical to understanding errors that are generated by a macro.&amp;nbsp; There is nothing worse than having MPRINT turned off, and having an error in your log, and no idea what code is causing the error.&amp;nbsp; I think MPRINT should always be turned on.&amp;nbsp; I know some people like to turn off MPRINT (and even NOTES) sometimes in production code that they "know" works and this saves them from having a big log file, or speeds up the code some tiny amount because it doesn't have to write a big log file.&amp;nbsp; I was the taught that the value of having a useful log file far outweighs any benefits that come from having a small log file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, when you turn on MPRINT, you should see that your code is generating a MODEL statement like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;model ln_bmi_medians ln_waist_median_cm ln_waist_hip_median = brinda15 / type3 dist=normal ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And that makes clear that you intended to have only one dependent variable on the MODEL statement, but have accidentally listed all three.&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2024 18:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929676#M41737</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-05-25T18:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with genmod macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929679#M41738</link>
      <description>Thank you so much! I was not aware of the mprint option. I'll make sure to turn it on from now on.</description>
      <pubDate>Sat, 25 May 2024 22:27:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929679#M41738</guid>
      <dc:creator>Stanley3</dc:creator>
      <dc:date>2024-05-25T22:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with genmod macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929684#M41739</link>
      <description>&lt;P&gt;thank you! that solved it. Now it's doing the cycle for all. my outcome variables. However, it is not working for a piece of my code below (which I omitted in the original question for simplicity). Using the mprint option, I can see that the macro-generated code does not seem to recognize &amp;amp;selected_var. I wonder if you know what could be wrong.&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;%macro geomeans (data=, outcome=);

%let total_vars = %sysfunc (countw (&amp;amp;outcome) );
%do i = 1 %to &amp;amp;total_vars;
%let selected_var=%scan (&amp;amp;outcome, &amp;amp;i);

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ods output estimates=geomeans&amp;amp;i;&amp;nbsp;
proc genmod data=&amp;amp;data;
class brinda15 / param = glm;
&amp;nbsp; &amp;nbsp; &amp;nbsp; model &amp;amp;selected_var = brinda15 / type3 dist=normal ;
estimate "Overall estimate &amp;amp;selected_var brinda15 =0" intercept 1 brinda15 1 0 &amp;nbsp;/exp;&amp;nbsp;
estimate "Overall estimate &amp;amp;selected_var brinda15 =1" intercept 1 brinda15 0 1 &amp;nbsp;/exp;&amp;nbsp;
by rural;
run;
ods output close;

data geomeans&amp;amp;i; set geomeans&amp;amp;i;&amp;nbsp;
variable='&amp;amp;selected_var';&amp;nbsp;
lower=LBetaEstimate - stderr; &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; &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; &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
upper=LBetaEstimate + stderr;
if rural=0 then setting='urban'; else if rural=1 then setting='rural';
if (label='Exp(Overall estimate &amp;amp;selected_var brinda15 =0)') then iron_def=0;&amp;nbsp;
else if (label='Exp(Overall estimate &amp;amp;selected_var brinda15 =1)') then iron_def=1;
if iron_def=. then delete;
if iron_def=0 then iron_status='serum ferritin &amp;nbsp;≥15 µg';&amp;nbsp;
else if iron_def=1 then iron_status='serum ferritin &amp;lt;15 µg';
keep label iron_def variable LBetaEstimate StdErr lower upper rural iron_status setting;
run;

quit;
&amp;nbsp; &amp;nbsp; %end;

%mend;&lt;/PRE&gt;Log&amp;nbsp;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-05-25 at 9.32.47 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96766i0BD063237E2C0DD9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-05-25 at 9.32.47 PM.png" alt="Screenshot 2024-05-25 at 9.32.47 PM.png" /&gt;&lt;/span&gt;&lt;P&gt; &lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 26 May 2024 01:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929684#M41739</guid>
      <dc:creator>Stanley3</dc:creator>
      <dc:date>2024-05-26T01:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with genmod macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929685#M41740</link>
      <description>&lt;P&gt;Thank you, this is life-changing!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2024 01:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929685#M41740</guid>
      <dc:creator>Stanley3</dc:creator>
      <dc:date>2024-05-26T01:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with genmod macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929692#M41741</link>
      <description>&lt;P&gt;Macro variables will not resolve inside of single quotes.&amp;nbsp; So change:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;variable='&amp;amp;selected_var';&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;to:&lt;/P&gt;
&lt;PRE&gt;variable="&amp;amp;selected_var";&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;and be sure to do the same for the quoted strings on your IF statements as well.&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2024 02:36:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929692#M41741</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-05-26T02:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with genmod macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929694#M41742</link>
      <description>&lt;P&gt;Thank you so much!! It runs great now&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2024 02:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Problem-with-genmod-macro/m-p/929694#M41742</guid>
      <dc:creator>Stanley3</dc:creator>
      <dc:date>2024-05-26T02:52:44Z</dc:date>
    </item>
  </channel>
</rss>

