<?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: call a macro inside a macro with do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586355#M167391</link>
    <description>&lt;P&gt;Modify your call execute like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%freq(DATASET = b2,VAR=',"&amp;amp;varname.,_,OUTDS=d_&amp;amp;varname.))"));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The %nrstr prevents timing problems caused by mixed Base SAS/macro code, and the double quotes around the second part of the call allow resolution of macro variable &amp;amp;varname. Macro triggers are not resolved when enclosed by single quotes.&lt;/P&gt;</description>
    <pubDate>Thu, 05 Sep 2019 10:12:37 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-09-05T10:12:37Z</dc:date>
    <item>
      <title>call a macro inside a macro with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586337#M167381</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test1(s);&lt;BR /&gt;%do i=1 %to %sysfunc(countw(&amp;amp;s,%str( ),q));&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %let varname =%scan(&amp;amp;s,&amp;amp;i.);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; call execute('%freq(DATASET = b2,VAR=&amp;amp;varname.,_,OUTDS=d_&amp;amp;varname.)');&lt;BR /&gt;%end;&lt;BR /&gt;%mend test1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%test1(a b c d e f g) ;&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;/* like a b c d e f g ,&amp;nbsp; &amp;nbsp; I have 35 variables to pass */&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm getting an error :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VARNAME=a&lt;BR /&gt;NOTE: Line generated by the invoked macro "TEST1".&lt;BR /&gt;37 call execute('%freq(DATASET = b2,VAR=&amp;amp;varname.,&lt;BR /&gt;37 OUTDS=d_&amp;amp;varname.)');&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;VARNAME=b&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the invoked macro "TEST1".&lt;BR /&gt;37 call execute('%freq(DATASET = b2,VAR=&amp;amp;varname.,&lt;BR /&gt;37 OUTDS=d_&amp;amp;varname.)');&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;VARNAME=c&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the invoked macro "TEST1".&lt;BR /&gt;37 call execute('%freq(DATASET = b2,VAR=&amp;amp;varname.,&lt;BR /&gt;37 OUTDS=d_&amp;amp;varname.)');&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 08:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586337#M167381</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2019-09-05T08:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside a macro with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586355#M167391</link>
      <description>&lt;P&gt;Modify your call execute like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%freq(DATASET = b2,VAR=',"&amp;amp;varname.,_,OUTDS=d_&amp;amp;varname.))"));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The %nrstr prevents timing problems caused by mixed Base SAS/macro code, and the double quotes around the second part of the call allow resolution of macro variable &amp;amp;varname. Macro triggers are not resolved when enclosed by single quotes.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 10:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586355#M167391</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-05T10:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside a macro with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586356#M167392</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/109034"&gt;@sahoositaram555&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CALL EXECUTE can only be used in a DATA step. So, if macro &lt;FONT face="courier new,courier"&gt;test1&lt;/FONT&gt; is not called within a DATA step, don't use CALL EXECUTE, but simply call the inner macro as usual: &lt;FONT face="courier new,courier"&gt;%freq(DATASET=...)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;(no semicolon required).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The underscore (positional parameter between keyword parameters VAR and OUTDS? Not occurring in your log excerpt, though.) is likely to produce further error messages, but these will have nothing to do with the outer macro.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 10:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586356#M167392</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-09-05T10:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside a macro with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586359#M167394</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;,&lt;BR /&gt;I'm getting a new type of error. Kindly have a look.&lt;BR /&gt;&lt;BR /&gt;VARNAME=a&lt;BR /&gt;180: LINE and COLUMN cannot be determined.&lt;BR /&gt;NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;&lt;BR /&gt;VARNAME=b&lt;BR /&gt;180: LINE and COLUMN cannot be determined.&lt;BR /&gt;NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Sep 2019 10:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586359#M167394</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2019-09-05T10:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside a macro with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586363#M167395</link>
      <description>&lt;P&gt;Please post&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the code of macro %freq&lt;/LI&gt;
&lt;LI&gt;the complete code of the data step in which you use macro %test1&lt;/LI&gt;
&lt;LI&gt;a sample of the input data used in that data step&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 05 Sep 2019 10:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586363#M167395</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-05T10:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside a macro with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586393#M167403</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;,&lt;BR /&gt;Thanks your for your help. Due to policy issues i really cant share the % freq macro.How ever, I have modified the code by the reference that you have given, and checked that a perticular type of syntax error is coming for all the variables.&lt;BR /&gt;&lt;BR /&gt;kindly have a look to my full code and the log error.&lt;BR /&gt;%macro test1(s=);&lt;BR /&gt;%do kk=1 %to %sysfunc(countw(&amp;amp;s,%str( ),q));&lt;BR /&gt;%let varname =%scan(&amp;amp;s,&amp;amp;kk.);&lt;BR /&gt;data dd_&amp;amp;varname.;&lt;BR /&gt;OPTIONS SPOOL;&lt;BR /&gt;call execute(cats('%nrstr(%freq(DATASET = b2,TRT=trt, TRTFMT =_NONE_ ,BYVAR = _NONE_,FMTVAR= _NONE_,COND= _NONE_,PCTTYPE= COL,P= _NONE_,DENOMNODISP = _NO_,&lt;BR /&gt;delALLDS= _YES_,MAXnumLEN= 6,clopper_pearson = _NONE_&lt;BR /&gt;VAR=' "&amp;amp;varname.,_,OUTDS=d_&amp;amp;varname.))"));&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend test1;&lt;BR /&gt;&lt;BR /&gt;%test1(s=a t s );&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Error in the log:&lt;BR /&gt;GOPTIONS ACCESSIBLE;&lt;BR /&gt;26 %test1(s=a t s);&lt;BR /&gt;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.DD_a may be incomplete. When this step was stopped there were 0 observations and 0 variables.&lt;BR /&gt;WARNING: Data set WORK.DD_a was not replaced because this step was stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;BR /&gt;&lt;BR /&gt;NOTE: Line generated by the macro variable "VARNAME".&lt;BR /&gt;26 "a,_,OUTDS=d_a&lt;BR /&gt;__________________&lt;BR /&gt;22&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE,&lt;BR /&gt;GT, LE, LT, MAX, MIN, NE, NG, NL, OR, ^=, |, ||, ~=.&lt;BR /&gt;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.DD_t may be incomplete. When this step was stopped there were 0 observations and 0 variables.&lt;BR /&gt;WARNING: Data set WORK.DD_t was not replaced because this step was stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;BR /&gt;&lt;BR /&gt;NOTE: Line generated by the macro variable "VARNAME".&lt;BR /&gt;26 "t,_,OUTDS=d_t&lt;BR /&gt;________________________&lt;BR /&gt;22&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE,&lt;BR /&gt;2 The SAS System 20:53 Thursday, September 5, 2019&lt;BR /&gt;&lt;BR /&gt;GT, LE, LT, MAX, MIN, NE, NG, NL, OR, ^=, |, ||, ~=.&lt;BR /&gt;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.s may be incomplete. When this step was stopped there were 0 observations and 0 variables.&lt;BR /&gt;WARNING: Data set WORK.DD_s was not replaced because this step was stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;BR /&gt;&lt;BR /&gt;Kindly hep with your suggestion.</description>
      <pubDate>Thu, 05 Sep 2019 12:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586393#M167403</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2019-09-05T12:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside a macro with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586395#M167405</link>
      <description>&lt;P&gt;I think that you're keeping crucial parts of the log from us, as you use one positional parameter in the %freq call, while all others are named. That usually does not work as intended.&lt;/P&gt;
&lt;P&gt;I've stripped your code down to the bare essentials, and it works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro freq(dataset=,var=,outds=);
%put dataset=&amp;amp;dataset;
%put var=&amp;amp;var;
%put outds=&amp;amp;outds;
%mend;

%macro test1(s);
%do i=1 %to %sysfunc(countw(&amp;amp;s,%str( ),q));
    %let varname =%scan(&amp;amp;s,&amp;amp;i.);
    call execute(cats('%nrstr(%freq(DATASET = b2,VAR=',"&amp;amp;varname.,OUTDS=d_&amp;amp;varname.))"));
%end;
%mend test1;

data _null_;
%test1(a b c d e f g)
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Take this code and expand from there.&lt;/P&gt;
&lt;P&gt;Before putting code in a macro, make sure that it works without all the macro code.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 12:21:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586395#M167405</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-05T12:21:12Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside a macro with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586397#M167407</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/109034"&gt;@sahoositaram555&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The post in this thread by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;is the answer you want.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 12:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586397#M167407</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-05T12:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside a macro with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586403#M167408</link>
      <description>&lt;P&gt;You're missing a comma in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%freq(DATASET = b2,TRT=trt, TRTFMT =_NONE_ ,BYVAR = _NONE_,FMTVAR= _NONE_,COND= _NONE_,PCTTYPE= COL,P= _NONE_,DENOMNODISP = _NO_,
delALLDS= _YES_,MAXnumLEN= 6,clopper_pearson = _NONE_
VAR=' &lt;BR /&gt;&lt;FONT size="6" color="#FF0000"&gt;&lt;STRONG&gt;, /*need comma here*/&lt;BR /&gt;&lt;/STRONG&gt;&lt;/FONT&gt;"&amp;amp;varname.,_,OUTDS=d_&amp;amp;varname.))"));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But more importantly, you don't need call execute here, and it makes the code harder to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You've already written a macro %DO loop.&amp;nbsp; Within that loop you can call %FREQ.&amp;nbsp; You don't need a DATA STEP and CALL EXECUTE, since you're not reading any data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is an example like yours, modified to just call %FREQ within the %DO loop:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test1(data=,var=);
%local i varname;
%do i=1 %to %sysfunc(countw(&amp;amp;var,%str( ),q));
  %let varname =%scan(&amp;amp;var,&amp;amp;i,%str( ),q);
  %put &amp;amp;=i &amp;amp;=varname ;
  %freq(data =&amp;amp;data,VAR=&amp;amp;varname)
%end;
%mend test1;

%macro freq(data=,var=) ;
  proc freq data=&amp;amp;data ;
    tables &amp;amp;var ;
  run ;
%mend freq ;

options mprint ;
%test1(data=sashelp.shoes,var=Product Region Returns)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 12:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-a-macro-with-do-loop/m-p/586403#M167408</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-09-05T12:40:49Z</dc:date>
    </item>
  </channel>
</rss>

