<?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: Why the code fails inside macro but ok not in macro?! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-the-code-fails-inside-macro-but-ok-not-in-macro/m-p/930785#M366194</link>
    <description>&lt;P&gt;Works for me. Verify that both of your variables are of type numeric.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hs300_0604;
  if=2; dlastprice=1;output;
  if=4; dlastprice=3;output;
run;

proc sql noprint;
  select avg(IF)-avg(dlastprice) into :lpadj 
  from hs300_0604
  ;
quit;
%put &amp;amp;=lpadj;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;38         %put &amp;amp;=lpadj;
LPADJ=       1
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Update: As a reaction on what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;posted (worth testing) the code also works for me within a macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hs300_0604;
  if=2; dlastprice=1;output;
  if=4; dlastprice=3;output;
run;

%macro doit(param1,param2);
  proc sql noprint;
    select avg(&amp;amp;param1)-avg(&amp;amp;param2) into :lpadj 
    from hs300_0604
    ;
  quit;
  %put &amp;amp;=lpadj;
%mend;

options mprint;
%doit(if,dlastprice);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;MPRINT(DOIT):   proc sql noprint;
MPRINT(DOIT):   select avg(if)-avg(dlastprice) into :lpadj from hs300_0604 ;
MPRINT(DOIT):   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

LPADJ=       1&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Jun 2024 12:24:32 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-06-04T12:24:32Z</dc:date>
    <item>
      <title>Why the code fails inside macro but ok not in macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-code-fails-inside-macro-but-ok-not-in-macro/m-p/930780#M366190</link>
      <description>&lt;PRE&gt;The code is straightforward, to get the dif from two variables. The dataset has the two variables, which are both&lt;BR /&gt;&lt;CODE class=" language-sas"&gt;of numeric. &lt;BR /&gt;&lt;BR /&gt;But the one inside marco complains. The "same" code works ok without macro.&lt;BR /&gt;&lt;BR /&gt;Anyone?!

&lt;BR /&gt;&lt;BR /&gt;MPRINT(DOLOOP):   proc sql ;
MPRINT(DOLOOP):   select avg(IF)-avg(dlastprice) into: lpadj from hs300_0604 ;
ERROR: The AVG summary function requires a numeric argument.
MPRINT(DOLOOP):   quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

59956  proc sql;
59957  select avg(IF)-avg(dlastprice)  from hs300_0604 ;
59958  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jun 2024 10:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-code-fails-inside-macro-but-ok-not-in-macro/m-p/930780#M366190</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2024-06-04T10:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Why the code fails inside macro but ok not in macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-code-fails-inside-macro-but-ok-not-in-macro/m-p/930781#M366191</link>
      <description>&lt;P&gt;Anyway/Macro to tell which one variable at a dataset is numeric or not?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So can use ahead of the SQL to avoid complains?!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2024 10:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-code-fails-inside-macro-but-ok-not-in-macro/m-p/930781#M366191</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2024-06-04T10:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Why the code fails inside macro but ok not in macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-code-fails-inside-macro-but-ok-not-in-macro/m-p/930785#M366194</link>
      <description>&lt;P&gt;Works for me. Verify that both of your variables are of type numeric.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hs300_0604;
  if=2; dlastprice=1;output;
  if=4; dlastprice=3;output;
run;

proc sql noprint;
  select avg(IF)-avg(dlastprice) into :lpadj 
  from hs300_0604
  ;
quit;
%put &amp;amp;=lpadj;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;38         %put &amp;amp;=lpadj;
LPADJ=       1
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Update: As a reaction on what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;posted (worth testing) the code also works for me within a macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hs300_0604;
  if=2; dlastprice=1;output;
  if=4; dlastprice=3;output;
run;

%macro doit(param1,param2);
  proc sql noprint;
    select avg(&amp;amp;param1)-avg(&amp;amp;param2) into :lpadj 
    from hs300_0604
    ;
  quit;
  %put &amp;amp;=lpadj;
%mend;

options mprint;
%doit(if,dlastprice);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;MPRINT(DOIT):   proc sql noprint;
MPRINT(DOIT):   select avg(if)-avg(dlastprice) into :lpadj from hs300_0604 ;
MPRINT(DOIT):   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

LPADJ=       1&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2024 12:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-code-fails-inside-macro-but-ok-not-in-macro/m-p/930785#M366194</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-06-04T12:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Why the code fails inside macro but ok not in macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-code-fails-inside-macro-but-ok-not-in-macro/m-p/930791#M366199</link>
      <description>&lt;P&gt;inside your macro code make it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select %unquote(avg(&amp;amp;whatEverMacrovariabeYouHaveHere.)-%unquote(avg(&amp;amp;whatOtherMacrovariabeYouHaveThere.))
into ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2024 12:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-code-fails-inside-macro-but-ok-not-in-macro/m-p/930791#M366199</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-06-04T12:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Why the code fails inside macro but ok not in macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-code-fails-inside-macro-but-ok-not-in-macro/m-p/930792#M366200</link>
      <description>&lt;P&gt;And if I was right, read this article by Susan O'Connor:&amp;nbsp;&lt;A href="https://stats.oarc.ucla.edu/wp-content/uploads/2016/02/bt185.pdf" target="_blank"&gt;https://stats.oarc.ucla.edu/wp-content/uploads/2016/02/bt185.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2024 12:03:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-code-fails-inside-macro-but-ok-not-in-macro/m-p/930792#M366200</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-06-04T12:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: Why the code fails inside macro but ok not in macro?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-code-fails-inside-macro-but-ok-not-in-macro/m-p/930822#M366212</link>
      <description>&lt;P&gt;Hard to tell since you did not provide the macro.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2024 15:08:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-code-fails-inside-macro-but-ok-not-in-macro/m-p/930822#M366212</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-04T15:08:57Z</dc:date>
    </item>
  </channel>
</rss>

