<?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 Parameter not Executing - Help :) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813110#M320851</link>
    <description>&lt;P&gt;Thanks so much for the reply. Allergies is the name of a numeric category (binary 1=yes, 0=No). The code works the first time with any variable. It's the second time that I try and run it that it won't.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 May 2022 01:18:16 GMT</pubDate>
    <dc:creator>agille05</dc:creator>
    <dc:date>2022-05-13T01:18:16Z</dc:date>
    <item>
      <title>Macro Parameter not Executing - Help :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813107#M320848</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hoping someone can help me. I've just about finished developing a macro code, but it isn't working for just one of my parameters (all others seem to be working). The line that I'm having trouble with is the Compute line (&lt;EM&gt;Compute percapita; percapita=(&amp;amp;Dx.sum/population)*10000&lt;/EM&gt;). Based on my error messages, I have a feeling the computation is being stored somewhere and not being released when I execute a different macro parameter. I'm show the code and error message below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the code the first time it works (included the entire macro for reference):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%Macro PerCapitaReport(Dx);
Proc Report Data=Merge Missing;
   Where &amp;amp;Dx=1;
   Title "&amp;amp;Dx";
   Column Province &amp;amp;Dx, (n sum pctn) Population PerCapita Age, Mean;
   Define Province / group style (column) = Header;
   Define &amp;amp;Dx / sum;
   Define n / 'Count' f=comma6.;
   Define sum / 'Sum';
   Define pctn / 'Percent' f=percent9.2;
   Define population / 'Population' group style (column) = Header f=comma12.;
   Define percapita / computed 'Rate Per/10,000 Population' f=12.2;
   Define age / 'Mean Age' f=9.;
   Rbreak after / summarize style(summary) = Header;
   Compute percapita; percapita=(&amp;amp;Dx.sum/population)*10000;
   Endcomp;
   Compute After; Province = 'Total';
   Endcomp;
Run;
%Mend PerCapitaReport;

%PerCapitaReport(Allergies)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then when I try a different parameter (see code below)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%PerCapitaReport(Cancer)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is the error report:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1243 %PerCapitaReport(Cancer)&lt;/P&gt;&lt;P&gt;ERROR: The variable type of 'ALLERGIES.SUM'n is invalid in this context.&lt;BR /&gt;NOTE: The preceding messages refer to the COMPUTE block for PerCapita.&lt;BR /&gt;NOTE: Will not run due to compilation errors.&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: There were 4984 observations read from the data set MERGE.&lt;BR /&gt;WHERE Cancer=1;&lt;BR /&gt;NOTE: PROCEDURE REPORT used (Total process time):&lt;BR /&gt;real time 0.06 seconds&lt;BR /&gt;cpu time 0.06 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate any assistance anyone can offer. Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 00:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813107#M320848</guid>
      <dc:creator>agille05</dc:creator>
      <dc:date>2022-05-13T00:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter not Executing - Help :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813109#M320850</link>
      <description>What is the type of the variable, Allergies? I suspect it's a character type when summaries require numeric variables.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 13 May 2022 01:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813109#M320850</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-05-13T01:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter not Executing - Help :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813110#M320851</link>
      <description>&lt;P&gt;Thanks so much for the reply. Allergies is the name of a numeric category (binary 1=yes, 0=No). The code works the first time with any variable. It's the second time that I try and run it that it won't.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 01:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813110#M320851</guid>
      <dc:creator>agille05</dc:creator>
      <dc:date>2022-05-13T01:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter not Executing - Help :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813113#M320852</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you posted isn't matching up with the error you posted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please turn on OPTIONS MPRINT: and post the log from the first time you called the macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%PerCapitaReport(Allergies)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That macro call should generate:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Report Data=Merge Missing;
   Where Allergies=1;
   Title "Allergies";
   Column Province Allergies, (n sum pctn) Population PerCapita Age, Mean;
   Define Province / group style (column) = Header;
   Define Allergies / sum;
   Define n / 'Count' f=comma6.;
   Define sum / 'Sum';
   Define pctn / 'Percent' f=percent9.2;
   Define population / 'Population' group style (column) = Header f=comma12.;
   Define percapita / computed 'Rate Per/10,000 Population' f=12.2;
   Define age / 'Mean Age' f=9.;
   Rbreak after / summarize style(summary) = Header;
   Compute percapita; percapita=(Allergiessum/population)*10000;  /*Note the problem on this line*/
   Endcomp;
   Compute After; Province = 'Total';
   Endcomp;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which I expect would error, because it will look for a variable named Allergiessum which I assume doesn't exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would start there as a first step.&amp;nbsp; And get it working for one variable.&amp;nbsp; After that, if it doesn't work for a different variable, copy the code from the log (showed by the MPRINT) into your code window and try submitting it.&amp;nbsp; It's either to debug non-macro code than macro code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't use COMPUTE blocks a lot, but I think you need a dot in your code for Allergies.sum.&amp;nbsp; When you reference a macro variable a dot and the end of the macro variable name indicates the end of the macro variable.&amp;nbsp; That dot is part of the macro language, it is not a SAS language dot.&amp;nbsp; If you want a SAS language dot, you need to type a second dot, i.e.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   Compute percapita; percapita=(&amp;amp;Dx..sum/population)*10000;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 May 2022 01:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813113#M320852</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-05-13T01:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter not Executing - Help :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813196#M320891</link>
      <description>&lt;P&gt;Good morning and thank you so much for your help Quentin. I've turned on&amp;nbsp;&lt;SPAN&gt;OPTIONS MPRINT as you directed, and this is log report after calling the macro. I also did try the second dot, but that didn't make a difference. It's definitely just this one part of the code that seems to be the issue (where the call removes the decimal from the code percapita =(&amp;amp;Dx.sum/population)*10000 changes to&amp;nbsp;percapita=(Diabetessum/population)*10000;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm just at a loss of what to do (also still a beginning learner. Background is in nursing actually ... but doing my best &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;56 %PerCapitaReport(Diabetes)&lt;BR /&gt;NOTE: Writing HTML Body file: sashtml.htm&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Proc Report Data=Merge Missing;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Where Diabetes=1;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Title "Diabetes";&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Column Province Diabetes, (n sum pctn) Population PerCapita Age, Mean;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Define Province / group style (column) = Header;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Define Diabetes / sum;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Define n / 'Count' f=comma6.;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Define sum / 'Sum';&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Define pctn / 'Percent' f=percent9.2;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Define population / 'Population' group style (column) = Header&lt;BR /&gt;f=comma12.;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Define percapita / computed 'Rate Per/10,000 Population' f=12.2;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Define age / 'Mean Age' f=9.;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Rbreak after / summarize style(summary) = Header;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Compute percapita;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): percapita=(Diabetessum/population)*10000;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Endcomp;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Compute After;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Province = 'Total';&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Endcomp;&lt;BR /&gt;MPRINT(PERCAPITAREPORT): Run;&lt;/P&gt;&lt;P&gt;NOTE: Variable Diabetessum is uninitialized.&lt;BR /&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;14 at 1:24&lt;BR /&gt;NOTE: There were 44882 observations read from the data set MERGE.&lt;BR /&gt;WHERE Diabetes=1;&lt;BR /&gt;NOTE: PROCEDURE REPORT used (Total process time):&lt;BR /&gt;real time 0.75 seconds&lt;BR /&gt;cpu time 0.23 seconds&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 13:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813196#M320891</guid>
      <dc:creator>agille05</dc:creator>
      <dc:date>2022-05-13T13:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter not Executing - Help :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813211#M320893</link>
      <description>&lt;PRE&gt;NOTE: Variable Diabetessum is uninitialized.&lt;/PRE&gt;
&lt;P&gt;In PROC REPORT, you can't use a variable unless it is in the COLUMNS statement, and in the COLUMNS it must be to the left of the variable you are trying to compute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Column Province diabetessum Diabetes, (n sum pctn) Population PerCapita Age, Mean;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You would probably also need&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;define diabetessum/noprint;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 May 2022 13:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813211#M320893</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-13T13:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter not Executing - Help :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813215#M320894</link>
      <description>&lt;P&gt;Thank you Paige. The diagnosis variable is already defined (Define &amp;amp;Dx / sum;). The diabetessum isn't a variable in my code (it's incorrectly generated when I call the macro because the decimal place gets dropped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code works without the Macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 13:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813215#M320894</guid>
      <dc:creator>agille05</dc:creator>
      <dc:date>2022-05-13T13:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter not Executing - Help :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813219#M320895</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/425008"&gt;@agille05&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;it's incorrectly generated when I call the macro because the decimal place gets dropped.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is because a dot within a string terminates the name of a macro variable. This is needed so you can build strings out of variable and fixed parts.&lt;/P&gt;
&lt;P&gt;Quick and simple example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a = x;
%let b = y;
/* this works */
%let c = &amp;amp;a._&amp;amp;b.;
%put &amp;amp;=c.;
/* this does not work */
%let c = &amp;amp;a_&amp;amp;b;
/* this works, and leaves a dot in the string */
%let c = &amp;amp;a..&amp;amp;b.;
%put &amp;amp;=c.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See Maxim 48.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your COMPUTE block must be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;compute percapita;
  percapita = (&amp;amp;Dx..sum / population) * 10000;
endcomp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Blanks (whitespace) help in making code more readable.&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 13:41:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813219#M320895</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-13T13:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter not Executing - Help :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813220#M320896</link>
      <description>&lt;P&gt;If you copy the code from your MPRINT and add just one dot, does that code work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Report Data=Merge Missing;
Where Diabetes=1;
Title "Diabetes";
Column Province Diabetes, (n sum pctn) Population PerCapita Age, Mean;
Define Province / group style (column) = Header;
Define Diabetes / sum;
Define n / 'Count' f=comma6.;
Define sum / 'Sum';
Define pctn / 'Percent' f=percent9.2;
Define population / 'Population' group style (column) = Header f=comma12.;
Define percapita / computed 'Rate Per/10,000 Population' f=12.2;
Define age / 'Mean Age' f=9.;
Rbreak after / summarize style(summary) = Header;
Compute percapita;
percapita=(Diabetes.sum/population)*10000;   /* Add a dot here in Diabetes.sum*/
Endcomp;
Compute After;
Province = 'Total';
Endcomp;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If so, then my suggestion to add a dot should work.&amp;nbsp; Since you are new to macro, one thing to remember is after you make a change to the code in the macro definition, you need to remember to highlight and submit the macro definition, so that the macro is compiled using the updated code.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you still have a problem, please post longer log, where the log shows the macro definition and the macro call and the log messages after the macro call.&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 13:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813220#M320896</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-05-13T13:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter not Executing - Help :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813226#M320900</link>
      <description>&lt;P&gt;Awesome. That was totally it. I didn't realize I had to run the macro after the change (I'm so sorry to have bothered you all... but so appreciate the assistance! You've made my Friday. Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 13:50:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-not-Executing-Help/m-p/813226#M320900</guid>
      <dc:creator>agille05</dc:creator>
      <dc:date>2022-05-13T13:50:19Z</dc:date>
    </item>
  </channel>
</rss>

