<?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 bug problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-bug-problem/m-p/644631#M192572</link>
    <description>&lt;P&gt;Are there errors in the log?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please put this command at the start of your program and then run it gain&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then post the ENTIRE log, by clicking on the &amp;lt;/&amp;gt; icon and paste the log as text into the window that appears. This maintains the formatting of the log and makes it much easier to read and understand . DO NOT SKIP THIS STEP.&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Fri, 01 May 2020 22:51:08 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-05-01T22:51:08Z</dc:date>
    <item>
      <title>Macro bug problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-bug-problem/m-p/644630#M192571</link>
      <description>&lt;P&gt;Hi guys. I have a bug problem I cannot fix, this is my code. productname is a macro variable "a b c d" and sqlobs is 4 in my case. My logic is using macro do loop and %scan function to scan the product name each time and output the data using proc report step. But when I run the data, nothing comes out. I don't know why?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data order;
input ordernumber$ product$ qrt;
cards;
##1 a 1000
##2 b 200
##3 c 3000
##4 d 200
;
run;

proc sql;
select distinct product into: productname separated by ' '
from order;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro report;
%do i=1 %to &amp;amp;sqlobs;%macro a; %mend a;
%Let name=%scan(productname,&amp;amp;i,' ');

proc print data=order;
var ordernumber qrt; 
where Product="&amp;amp;name";
title '&amp;amp;name';
run;

%end;
%mend;
%report;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 May 2020 22:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-bug-problem/m-p/644630#M192571</guid>
      <dc:creator>shawn123</dc:creator>
      <dc:date>2020-05-01T22:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Macro bug problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-bug-problem/m-p/644631#M192572</link>
      <description>&lt;P&gt;Are there errors in the log?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please put this command at the start of your program and then run it gain&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then post the ENTIRE log, by clicking on the &amp;lt;/&amp;gt; icon and paste the log as text into the window that appears. This maintains the formatting of the log and makes it much easier to read and understand . DO NOT SKIP THIS STEP.&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Fri, 01 May 2020 22:51:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-bug-problem/m-p/644631#M192572</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-01T22:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro bug problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-bug-problem/m-p/644632#M192573</link>
      <description>&lt;P&gt;First thing is you are not %scanning the macro variable. When you use this code&lt;/P&gt;
&lt;PRE&gt;%Let name=%scan(productname,&amp;amp;i,' ');&lt;/PRE&gt;
&lt;P&gt;You scan the literal text. To use the macro variable:&lt;/P&gt;
&lt;PRE&gt;%Let name=%scan(&amp;amp;productname,&amp;amp;i,' ');&lt;/PRE&gt;
&lt;P&gt;I have no idea what you intend with the&lt;/P&gt;
&lt;PRE&gt;%macro a; %mend a;&lt;/PRE&gt;
&lt;P&gt;but it is likely a poor idea. Recompiling macros inside another macro is one road to macro madness.&lt;/P&gt;
&lt;P&gt;Your title will not render as desired because you have the macro variable inside single quotes in&lt;/P&gt;
&lt;PRE&gt;title '&amp;amp;name';&lt;/PRE&gt;
&lt;P&gt;Better practice would be to either place the Proc SQL inside the macro OR to make the Productname macro variable a parameter passed to the macro. Having macro variables appear in code without an obvious source can be difficult to debug later. And you don't actually need the SQLObs variable.&lt;/P&gt;
&lt;PRE&gt;%do i=1 %to %sysfunc(countw(&amp;amp;productname));&lt;/PRE&gt;
&lt;P&gt;will count the number of space delimited words in &amp;amp;productname and use that as the limit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 22:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-bug-problem/m-p/644632#M192573</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-01T22:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro bug problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-bug-problem/m-p/644633#M192574</link>
      <description>&lt;P&gt;Hi ballardw, thank you so much for the quick reply.&lt;BR /&gt;Adding %macro a; %mend a; will let the SAS highlight the function for you. Easy to read. But thank you so much for the alternative way. Learn form this!&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 23:05:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-bug-problem/m-p/644633#M192574</guid>
      <dc:creator>shawn123</dc:creator>
      <dc:date>2020-05-01T23:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Macro bug problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-bug-problem/m-p/644661#M192590</link>
      <description>&lt;P&gt;You don't need any macro coding for this. Sort by product, and use proc report or proc print with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by product;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 May 2020 06:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-bug-problem/m-p/644661#M192590</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-02T06:27:40Z</dc:date>
    </item>
  </channel>
</rss>

