<?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: Format for a macro with multiple parmaters in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Format-for-a-macro-with-multiple-parmaters/m-p/639616#M78233</link>
    <description>&lt;P&gt;Your macro as written doesn't need any branching.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use the value of the macro variable at the appropriate place in the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO create_Table(y,statistic);
%local i;
%DO i = 1 %TO 10;
* Use PROC MEANS to generate requested statistic ;
PROC MEANS DATA = table_&amp;amp;y&amp;amp;i &amp;amp;statistic noprint;
	BY year;
	VAR var_&amp;amp;y&amp;amp;i ;
	OUTPUT OUT = stat_&amp;amp;y&amp;amp;i &amp;amp;statistic(var_&amp;amp;y&amp;amp;i) = var_&amp;amp;y&amp;amp;i ;
RUN; 
*Insert more code that works fine;
%END
%MEND create_Table;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can even get rid of the %DO loop.&amp;nbsp; Put all 10 of your VAR_&amp;amp;Y.1 to 10 variables into one input dataset and generate the statistic for all of them in one PROC into one output dataset.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO create_Table(y,statistic);
* Use PROC MEANS to generate requested statistics ;
PROC MEANS DATA = table_&amp;amp;y &amp;amp;statistic noprint;
	BY year;
	VAR var_&amp;amp;y.1 - var_&amp;amp;y.10 ;
	OUTPUT OUT = stat_&amp;amp;y &amp;amp;statistic=;
RUN; 
*Insert more code that works fine;

%MEND create_Table;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 14 Apr 2020 00:44:27 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-04-14T00:44:27Z</dc:date>
    <item>
      <title>Format for a macro with multiple parmaters</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format-for-a-macro-with-multiple-parmaters/m-p/639598#M78227</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm currently trying to update a single-parameter macro, to two parameters.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The reason is that my initial macro creates a data-set, based on a certain summary statistic that I calculate inside the macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, I want to add a second parameter, that let's me call the macro and create a data-set based on a variety of summary statistics, but I am getting an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my original macro, I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO create_Table1(y);

%DO i = 1 %TO 10;

*Table 1 Calculate 10th percentile;
PROC MEANS DATA = table_&amp;amp;y&amp;amp;i p10 noprint;
	BY year;
	VAR var_&amp;amp;y&amp;amp;i ;
	OUTPUT OUT = stat_&amp;amp;y&amp;amp;i P10(var_&amp;amp;y&amp;amp;i) = var_&amp;amp;y&amp;amp;i ;
RUN; 

*Insert more code that works fine;
%END
%MEND create_Table1;

%create_table(y1);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This works fine for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, I want it so that I can call the macro to calculate either p10 or p50, based on my parameters.&lt;/P&gt;&lt;P&gt;So I tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO create_Table1(y=, statistic=);

%DO i = 1 %TO 10;


*Table 1 Calculate 10th percentile if statistic = p10;

	%IF &amp;amp;statistic=p10 %THEN 
%DO;
PROC MEANS DATA = table_&amp;amp;y&amp;amp;i p10 noprint;
	BY year;
	VAR var_&amp;amp;y&amp;amp;i ;
	OUTPUT OUT = stat_&amp;amp;y&amp;amp;i P10(var_&amp;amp;y&amp;amp;i) = var_&amp;amp;y&amp;amp;i ;
RUN; 
%END;

*Table 2 Calculate 50th percentile if statistic = p50;
	%ELSE %IF &amp;amp;statistic=p50 %THEN 
%DO;
PROC MEANS DATA = table_&amp;amp;y&amp;amp;i p50 noprint;
	BY year;
	VAR var_&amp;amp;y&amp;amp;i ;
	OUTPUT OUT = stat_&amp;amp;y&amp;amp;i P50(var_&amp;amp;y&amp;amp;i) = var_&amp;amp;y&amp;amp;i ;
RUN; 
%END;

*Insert more code that works fine;
%END
%MEND create_Table1;
&lt;BR /&gt;*Create table with 10th percentile;
%create_table1(y1,p10);&lt;BR /&gt;&lt;BR /&gt;*Create&amp;nbsp;table&amp;nbsp;with&amp;nbsp;50th&amp;nbsp;percentile;&lt;BR /&gt;%create_table1(y1,p50);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But when I try to mend my macro, I get an error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  %ELSE %IF &amp;amp;statistic=p50 %THEN 
ERROR: There is no matching %IF statement for the %ELSE.
ERROR: A dummy macro will be compiled.
2739  %DO;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So, I'm wondering, have I messed up the formatting here, or is there potentially another&lt;/P&gt;&lt;P&gt;issue at large?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Apr 2020 23:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format-for-a-macro-with-multiple-parmaters/m-p/639598#M78227</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2020-04-13T23:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Format for a macro with multiple parmaters</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format-for-a-macro-with-multiple-parmaters/m-p/639599#M78228</link>
      <description>&lt;P&gt;You cannot insert a statement between the %THEN clause and the %ELSE clause.&lt;/P&gt;
&lt;P&gt;To the macro processor your comment is a statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally I place the comments inside the macro code, not before them. Then they print in the log when the MPRINT option is on.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF &amp;amp;statistic=p10 %THEN  %DO;
*Table 1 Calculate 10th percentile if statistic = p10;
PROC MEANS DATA = table_&amp;amp;y&amp;amp;i p10 noprint;
	BY year;
	VAR var_&amp;amp;y&amp;amp;i ;
	OUTPUT OUT = stat_&amp;amp;y&amp;amp;i P10(var_&amp;amp;y&amp;amp;i) = var_&amp;amp;y&amp;amp;i ;
RUN; 
%END;

%ELSE %IF &amp;amp;statistic=p50 %THEN  %DO;
*Table 2 Calculate 50th percentile if statistic = p50;
...
%END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also use either a block comment or a macro comment and it wouldn't count as a statement in between.&amp;nbsp; But then they won't print in the SAS log when MPRINT is on and the users of your macro will have a harder time understanding the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Types of comments:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* SAS comment ;
/* Block comment */
%* Macro comment ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Apr 2020 23:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format-for-a-macro-with-multiple-parmaters/m-p/639599#M78228</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-13T23:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Format for a macro with multiple parmaters</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format-for-a-macro-with-multiple-parmaters/m-p/639605#M78229</link>
      <description>&lt;P&gt;You may want to look into the AUTONAME option when creating output data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please examine (print or view the table) the results of running this code on a data set you should have available:&lt;/P&gt;
&lt;PRE&gt;Proc means data=sashelp.class noprint;
   class sex;
   var height weight;
   output out=work.summary mean= max= min= std= / autoname;
run;&lt;/PRE&gt;
&lt;P&gt;The autoname appends the statistic to the variable name (assuming the variable name + _ + statistic is 32 or fewer characters) so you might be able to reduce the calls to proc means/summary in a different fashion by calling either all the statistics or all the variables or both at one time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really are only calling one statistic for one variable you can use &amp;lt;statistic&amp;gt;= ; with nothing else and the name of the output statistic is the variable name:&lt;/P&gt;
&lt;PRE&gt;Proc means data=sashelp.class noprint;
   class sex;
   var weight;
   output out=work.summary skew= ;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Apr 2020 23:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format-for-a-macro-with-multiple-parmaters/m-p/639605#M78229</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-13T23:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Format for a macro with multiple parmaters</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format-for-a-macro-with-multiple-parmaters/m-p/639606#M78230</link>
      <description>&lt;P&gt;Thanks, this solved it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would have never figured this out!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Apr 2020 23:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format-for-a-macro-with-multiple-parmaters/m-p/639606#M78230</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2020-04-13T23:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: Format for a macro with multiple parmaters</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Format-for-a-macro-with-multiple-parmaters/m-p/639616#M78233</link>
      <description>&lt;P&gt;Your macro as written doesn't need any branching.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use the value of the macro variable at the appropriate place in the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO create_Table(y,statistic);
%local i;
%DO i = 1 %TO 10;
* Use PROC MEANS to generate requested statistic ;
PROC MEANS DATA = table_&amp;amp;y&amp;amp;i &amp;amp;statistic noprint;
	BY year;
	VAR var_&amp;amp;y&amp;amp;i ;
	OUTPUT OUT = stat_&amp;amp;y&amp;amp;i &amp;amp;statistic(var_&amp;amp;y&amp;amp;i) = var_&amp;amp;y&amp;amp;i ;
RUN; 
*Insert more code that works fine;
%END
%MEND create_Table;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can even get rid of the %DO loop.&amp;nbsp; Put all 10 of your VAR_&amp;amp;Y.1 to 10 variables into one input dataset and generate the statistic for all of them in one PROC into one output dataset.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO create_Table(y,statistic);
* Use PROC MEANS to generate requested statistics ;
PROC MEANS DATA = table_&amp;amp;y &amp;amp;statistic noprint;
	BY year;
	VAR var_&amp;amp;y.1 - var_&amp;amp;y.10 ;
	OUTPUT OUT = stat_&amp;amp;y &amp;amp;statistic=;
RUN; 
*Insert more code that works fine;

%MEND create_Table;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Apr 2020 00:44:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Format-for-a-macro-with-multiple-parmaters/m-p/639616#M78233</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-14T00:44:27Z</dc:date>
    </item>
  </channel>
</rss>

