<?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: add a parameter to the macro that can control which variable is used for the report in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/add-a-parameter-to-the-macro-that-can-control-which-variable-is/m-p/604769#M175367</link>
    <description>&lt;P&gt;Of course you can.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you already know how to add parameters to a macro.&amp;nbsp; Next, you need to decide which parameters you want to add ... what the names of them will be and what the values will be that can be assigned to these parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you need to learn about %IF %THEN statements so the macro can use those parameters to control the results and titles.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this is a good learning exercise.&amp;nbsp; However, it is a poor choice for anything more than that.&amp;nbsp; You are better off writing PROC MEANS as needed instead of trying to convert your code to a macro.&amp;nbsp; Macros do not add to your knowledge of SAS.&amp;nbsp; Just the opposite.&amp;nbsp; They reduce your chance to become more familiar with the software by writing the program for you.&amp;nbsp; At this point, you would learn more by writing PROC MEANS yourself and postponing learning about macros.&lt;/P&gt;</description>
    <pubDate>Sun, 17 Nov 2019 02:45:08 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-11-17T02:45:08Z</dc:date>
    <item>
      <title>add a parameter to the macro that can control which variable is used for the report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-a-parameter-to-the-macro-that-can-control-which-variable-is/m-p/604763#M175361</link>
      <description>&lt;P&gt;I coverted a regular code (below)&amp;nbsp; into a macro that will produce either the frequency report or the descriptive&lt;BR /&gt;statistics report based on a value of a parameter that is passed to the macro.*/;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Original code&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token comment"&gt;/*frequency report for month*/&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;means&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;VIRGINIAKEY &lt;SPAN class="token function"&gt;N&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;month&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;class&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;month&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token comment"&gt;/*lists basic descriptive statistics (N, mean, standard deviation, minimum, and maximum) for air temperature*/&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;means&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;VIRGINIAKEY &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;  AirTemp&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Myy Current trial code:&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; freq_Describe &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;MNTH&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;month,&lt;/SPAN&gt; AIR_Temp&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;AirTemp &lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token comment"&gt;/*frequency report for month*/&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;means&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;VIRGINIAKEY &lt;SPAN class="token function"&gt;N&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;MNTH&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;class&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;MNTH&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token comment"&gt;/*lists basic descriptive statistics (N, mean, standard deviation, minimum, and maximum) for air temperature*/&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;means&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;VIRGINIAKEY &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;AIR_Temp&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt; freq_Describe&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="token macroname"&gt;%freq_Describe&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;MNTH&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;month&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; AIR_Temp&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;AirTemp&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is there a way to &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A) add a parameter to the macro that can control which variable is used for the report and &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;B) add titles that reflect the type of report (frequency or descriptive statistics) including a short&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;description of the variable (specifying the description of the variable as a parameter for the macro)?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice will be appreciated.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Nov 2019 00:23:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-a-parameter-to-the-macro-that-can-control-which-variable-is/m-p/604763#M175361</guid>
      <dc:creator>mrahouma</dc:creator>
      <dc:date>2019-11-17T00:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: add a parameter to the macro that can control which variable is used for the report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-a-parameter-to-the-macro-that-can-control-which-variable-is/m-p/604769#M175367</link>
      <description>&lt;P&gt;Of course you can.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you already know how to add parameters to a macro.&amp;nbsp; Next, you need to decide which parameters you want to add ... what the names of them will be and what the values will be that can be assigned to these parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you need to learn about %IF %THEN statements so the macro can use those parameters to control the results and titles.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this is a good learning exercise.&amp;nbsp; However, it is a poor choice for anything more than that.&amp;nbsp; You are better off writing PROC MEANS as needed instead of trying to convert your code to a macro.&amp;nbsp; Macros do not add to your knowledge of SAS.&amp;nbsp; Just the opposite.&amp;nbsp; They reduce your chance to become more familiar with the software by writing the program for you.&amp;nbsp; At this point, you would learn more by writing PROC MEANS yourself and postponing learning about macros.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Nov 2019 02:45:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-a-parameter-to-the-macro-that-can-control-which-variable-is/m-p/604769#M175367</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-11-17T02:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: add a parameter to the macro that can control which variable is used for the report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-a-parameter-to-the-macro-that-can-control-which-variable-is/m-p/604770#M175368</link>
      <description>&lt;P&gt;Here's an example of something you might do!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rpt(dsname,title,proc,cls,var,stats);

   ods noproctitle;
   title &amp;amp;title.;
   options nolabel;
   
   %if &amp;amp;proc.="means" %then %do;
   proc means data=&amp;amp;dsname. nonobs &amp;amp;stats.;
   class &amp;amp;cls.;
   var &amp;amp;var.;
   run;
   %end;
   
   %else %if &amp;amp;proc.="freq" %then %do;
   proc freq data=&amp;amp;dsname.;
   tables &amp;amp;var.(&amp;amp;cls.) / &amp;amp;stats.;
   run;
   %end;
   
%mend rpt;
*(dataset_name,"title","means/freq",class_vars,summary_vars,statistics/options);
%rpt(sashelp.cars, "My Means Summary!", "means", make, mpg_city, n std)
%rpt(sashelp.cars, "My Freq Summary!", "freq", make, mpg_city, nocol norow)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-unison&lt;/P&gt;</description>
      <pubDate>Sun, 17 Nov 2019 16:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-a-parameter-to-the-macro-that-can-control-which-variable-is/m-p/604770#M175368</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-17T16:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: add a parameter to the macro that can control which variable is used for the report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-a-parameter-to-the-macro-that-can-control-which-variable-is/m-p/604801#M175381</link>
      <description>&lt;P&gt;What is the purpose of writing such convoluted code?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rpt/parmbuff;
   %let dsname = %scan(&amp;amp;syspbuff,1,(,));
   %let title = %scan(&amp;amp;syspbuff,2,(,));
   %let proc = %scan(&amp;amp;syspbuff,3,(,));
   %let cls = %scan(&amp;amp;syspbuff,4,(,));
   %let var = %scan(&amp;amp;syspbuff,5,(,));
   %let stats = %scan(&amp;amp;syspbuff,6,(,));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just define the parameters in the %MACRO statement itself.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rpt(dsname,title,proc,cls,var,stats);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Nov 2019 15:54:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-a-parameter-to-the-macro-that-can-control-which-variable-is/m-p/604801#M175381</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-17T15:54:24Z</dc:date>
    </item>
    <item>
      <title>Re: add a parameter to the macro that can control which variable is used for the report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-a-parameter-to-the-macro-that-can-control-which-variable-is/m-p/604809#M175387</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;- that definitely does simplify things.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-unison&lt;/P&gt;</description>
      <pubDate>Sun, 17 Nov 2019 16:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-a-parameter-to-the-macro-that-can-control-which-variable-is/m-p/604809#M175387</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-17T16:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: add a parameter to the macro that can control which variable is used for the report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-a-parameter-to-the-macro-that-can-control-which-variable-is/m-p/605673#M175796</link>
      <description>&lt;P&gt;Thanks a lot for your efforts&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 11:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-a-parameter-to-the-macro-that-can-control-which-variable-is/m-p/605673#M175796</guid>
      <dc:creator>mrahouma</dc:creator>
      <dc:date>2019-11-20T11:14:47Z</dc:date>
    </item>
  </channel>
</rss>

