<?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: Combining two macros using a %do loop with a %if-%then-%do-%else-%do-%end loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200121#M37408</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with andreas_Ids solution&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;your two macro sub-routines do not appear to have the same parameters&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not a user of proc req &lt;/P&gt;&lt;P&gt;so I will not guess that your parameter named 'predict' is a variable name&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if parameter 'predict' is a variable name then consider this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro choose_verb(data = sashelp.class&lt;/P&gt;&lt;P&gt;,list_names = a b c d e f h);&lt;/P&gt;&lt;P&gt;%let n_items = %sysfunc(countw(&amp;amp;list_names));&lt;/P&gt;&lt;P&gt;%put echo &amp;amp;=n_items;&lt;/P&gt;&lt;P&gt;%do i = 1 %to &amp;amp;n_items;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %let item = %scan(&amp;amp;list_names,&amp;amp;i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %put echo &amp;amp;=item;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %*automagic: get type of variable;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %*let dsid = %sysfunc(open());&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %*let var_num = %sysfunc(varnum());&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %*let type = %sysfunc(vartype());&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %*let rc = %sysfunc(close());&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %let type = c;%*&amp;lt;---&amp;lt;&amp;lt;&amp;lt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %if &amp;amp;type eq c %then %put do_freq(data= &amp;amp;data,name = &amp;amp;item);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %else %put do_reg(data= &amp;amp;data,name = &amp;amp;item);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%choose_verb(data = work.all_del&lt;/P&gt;&lt;P&gt;,list_names = age sex height weight)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 08 Jun 2015 15:36:29 GMT</pubDate>
    <dc:creator>Ron_MacroMaven</dc:creator>
    <dc:date>2015-06-08T15:36:29Z</dc:date>
    <item>
      <title>Combining two macros using a %do loop with a %if-%then-%do-%else-%do-%end loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200115#M37402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I have two macros that I need to combine, I've been eyeing this thing for a while and can't seem to get it to work. It seems to be a simple step but I can't seem to get it recognize the new macro I create "Do_Freq_Req". The goal is to have the new macro "Do_Freq_Reg" execute as often as the number of variable in the analysis, and to have it branch into the Do_Freq and Do_Req macros that already exists. Below is the code of the two individual Do_Freq and Do_Reg macros.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;COMBINE THE NEXT TWO MACROS INTO ONE MACRO&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Macro Do_Freq(Input, Title);&lt;/P&gt;&lt;P&gt;Proc Freq Data= Alldel;&lt;/P&gt;&lt;P&gt; Tables &amp;amp;Input;&lt;/P&gt;&lt;P&gt;Title "Variable Summarized: &amp;amp;Title";&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;%Mend Do_Freq;&lt;/P&gt;&lt;P&gt;%Do_Freq(Hyperten, Hypertension during pregnancy?);&lt;/P&gt;&lt;P&gt;%Do_Freq(Diabetes, Prepregnancy diabetes?); &lt;/P&gt;&lt;P&gt;%Do_Freq(Gestatio, Gestational diabetes?);&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;%Do_Freq(Drug_Abu, Drugs use during pregnancy?);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;%Do_Freq(Smoke, Smoker?);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;%Do_Freq(HIV, HIV?);&lt;/P&gt;&lt;P&gt;%Do_Freq(Parity, Parity);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%MACRO DO_REG(Predict);&lt;/P&gt;&lt;P&gt; PROC REG DATA=ALLDEL;&lt;/P&gt;&lt;P&gt; &amp;amp;PREDICT: MODEL FETAL_WE=&amp;amp;PREDICT;&lt;/P&gt;&lt;P&gt; RUN;&lt;/P&gt;&lt;P&gt; QUIT;&lt;/P&gt;&lt;P&gt;%MEND DO_REG;&lt;/P&gt;&lt;P&gt;%DO_Reg(IndRace);&lt;/P&gt;&lt;P&gt;%Do_Reg(IndSmoke);&lt;/P&gt;&lt;P&gt;%Do_Reg(DeltaBmi)&lt;/P&gt;&lt;P&gt;%Do_Reg(Weeks_ge)&lt;/P&gt;&lt;P&gt;%Do_Reg(Age);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Jun 2015 20:10:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200115#M37402</guid>
      <dc:creator>arsn14</dc:creator>
      <dc:date>2015-06-04T20:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two macros using a %do loop with a %if-%then-%do-%else-%do-%end loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200116#M37403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This might help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.sas.com/content/publishing/2015/01/30/sas-authors-tip-getting-the-macro-language-to-perform-a-do-loop-over-a-list-of-values/"&gt;http://blogs.sas.com/content/publishing/2015/01/30/sas-authors-tip-getting-the-macro-language-to-perform-a-do-loop-over-a-list-of-values/&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Jun 2015 20:51:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200116#M37403</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-06-04T20:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two macros using a %do loop with a %if-%then-%do-%else-%do-%end loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200117#M37404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Astounding,&lt;/P&gt;&lt;P&gt;The link shows me how to do a loop, but I was wondering how do I join two different MACROS as listed above, into a single new MACRO with a do loop and a if and then statement included that would branch into the two individual MACROS&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Jun 2015 21:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200117#M37404</guid>
      <dc:creator>arsn14</dc:creator>
      <dc:date>2015-06-04T21:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two macros using a %do loop with a %if-%then-%do-%else-%do-%end loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200118#M37405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I suggest that you stick with your two macros.&lt;/P&gt;&lt;P&gt;Each is independent and therefore easy to test.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then what you need is a data set that has the list of criteria for calling each macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for your frequency macro,&lt;/P&gt;&lt;P&gt;that looks like variable name and label.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the tool to call the macro using a data set as list of parameters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://www.sascommunity.org/wiki/Macro_CallMacr" title="http://www.sascommunity.org/wiki/Macro_CallMacr"&gt;http://www.sascommunity.org/wiki/Macro_CallMacr&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For this tool to work&lt;/P&gt;&lt;P&gt;your list, control data set, has to have the variables the same as the macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I recommend that you use proc contents output data since that has (variable) name and label&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC contents data = &amp;amp;libname..&amp;amp;memname&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; noprint&lt;/P&gt;&lt;P&gt;&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; out&amp;nbsp; = out_contents&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (keep = memname name length&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type&amp;nbsp;&amp;nbsp;&amp;nbsp; length&amp;nbsp; format&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nobs&amp;nbsp;&amp;nbsp;&amp;nbsp; varnum&amp;nbsp; label&lt;/P&gt;&lt;P&gt;&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; rename = (nobs = _n_obs&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type = _type_n));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My style guide says: "always use named parameters in macros"&lt;/P&gt;&lt;P&gt;so this is my recommendation for your parameter names&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Macro Do_Freq(name=, label=);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*testing;&lt;/P&gt;&lt;P&gt;%callmacro(data = out_contents(keep = name label))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*auto-magic;&lt;/P&gt;&lt;P&gt;%callmacro(data = out_contents(keep = name label)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,macro_name=do_freq)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Jun 2015 00:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200118#M37405</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2015-06-05T00:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two macros using a %do loop with a %if-%then-%do-%else-%do-%end loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200119#M37406</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ron &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your reply, but I was wondering if I was to run a new macro with a 'if then statement' to call upon the stated Macros, how would I start that?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Jun 2015 01:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200119#M37406</guid>
      <dc:creator>arsn14</dc:creator>
      <dc:date>2015-06-05T01:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two macros using a %do loop with a %if-%then-%do-%else-%do-%end loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200120#M37407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Still hardly possible to know what you want to achieve by combining those two macros, because they have nothing in common except for the dataset used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Untested code ahead! */&lt;/P&gt;&lt;P&gt;%macro Container(Input=, Title=, Predict=);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if %length(&amp;amp;Input) &amp;gt; 0 and %length(&amp;amp;Title) &amp;gt; 0 %then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Do_Freq(&amp;amp;Input, &amp;amp;Title);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if %length(&amp;amp;Predict) &amp;gt; 0 %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %DO_REG(Predict);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Jun 2015 07:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200120#M37407</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2015-06-05T07:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two macros using a %do loop with a %if-%then-%do-%else-%do-%end loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200121#M37408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with andreas_Ids solution&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;your two macro sub-routines do not appear to have the same parameters&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not a user of proc req &lt;/P&gt;&lt;P&gt;so I will not guess that your parameter named 'predict' is a variable name&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if parameter 'predict' is a variable name then consider this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro choose_verb(data = sashelp.class&lt;/P&gt;&lt;P&gt;,list_names = a b c d e f h);&lt;/P&gt;&lt;P&gt;%let n_items = %sysfunc(countw(&amp;amp;list_names));&lt;/P&gt;&lt;P&gt;%put echo &amp;amp;=n_items;&lt;/P&gt;&lt;P&gt;%do i = 1 %to &amp;amp;n_items;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %let item = %scan(&amp;amp;list_names,&amp;amp;i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %put echo &amp;amp;=item;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %*automagic: get type of variable;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %*let dsid = %sysfunc(open());&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %*let var_num = %sysfunc(varnum());&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %*let type = %sysfunc(vartype());&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %*let rc = %sysfunc(close());&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %let type = c;%*&amp;lt;---&amp;lt;&amp;lt;&amp;lt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %if &amp;amp;type eq c %then %put do_freq(data= &amp;amp;data,name = &amp;amp;item);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %else %put do_reg(data= &amp;amp;data,name = &amp;amp;item);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%choose_verb(data = work.all_del&lt;/P&gt;&lt;P&gt;,list_names = age sex height weight)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 15:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-macros-using-a-do-loop-with-a-if-then-do-else-do/m-p/200121#M37408</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2015-06-08T15:36:29Z</dc:date>
    </item>
  </channel>
</rss>

