<?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: Defining a table title based on macro parameter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Defining-a-table-title-based-on-macro-parameter/m-p/797818#M313682</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/388382"&gt;@mgrasmussen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was not aware of the fact that I also needed a "%end" there. So, what was lacking was because of ignorance.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Every %DO has to have an associated %END;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Feb 2022 14:13:04 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-02-22T14:13:04Z</dc:date>
    <item>
      <title>Defining a table title based on macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defining-a-table-title-based-on-macro-parameter/m-p/797810#M313674</link>
      <description>&lt;P&gt;Dear SAS experts&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to create a table where the title is defined depending on the macro parameter specified. &lt;BR /&gt;Below is a simple example of scenario. If "M" is specified I would like a title specific for "M", &lt;BR /&gt;and the same for "F". I cannot get it to work, but I suspect I need to somehow use %if and %else in the macro. &lt;BR /&gt;Can someone help with the code? Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data mydata;&lt;BR /&gt;set sashelp.class;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*Creating tables;&lt;BR /&gt;%macro table(Sex=);&lt;/P&gt;
&lt;P&gt;proc means data=mydata;&lt;BR /&gt;var Age;&lt;BR /&gt;where Sex="&amp;amp;Sex.";&lt;BR /&gt;%if &amp;amp;Sex.="M" %then %do;&lt;BR /&gt;Title "Table of: &amp;amp;Sex. (M text)";&lt;BR /&gt;%else %do;&lt;BR /&gt;Title "Table of: &amp;amp;Sex. (F text)";&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%table(Sex=M);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%table(Sex=F);&lt;/P&gt;</description>
      <pubDate>Tue, 22 Feb 2022 13:54:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defining-a-table-title-based-on-macro-parameter/m-p/797810#M313674</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2022-02-22T13:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a table title based on macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defining-a-table-title-based-on-macro-parameter/m-p/797813#M313677</link>
      <description>&lt;P&gt;You have left out an &lt;FONT face="courier new,courier"&gt;%end;&lt;/FONT&gt; statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro table(Sex=);
    proc means data=mydata;
        var Age;
        where Sex="&amp;amp;Sex.";
        %if &amp;amp;Sex.="M" %then %do;
            Title "Table of: &amp;amp;Sex. (M text)";
        %end; /* This was left out and causes the problems */
        %else %do;
            Title "Table of: &amp;amp;Sex. (F text)";
        %end;
    run;
%mend;
%table(Sex=M)
%table(Sex=F)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you indent your code properly, as I have done, these types of errors become more obvious.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't really need a macro for this, simply a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sex=M;
proc means data=sashelp.class;
    var Age;
    where Sex="&amp;amp;sex";
    Title "Table of: &amp;amp;sex";
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Feb 2022 14:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defining-a-table-title-based-on-macro-parameter/m-p/797813#M313677</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-02-22T14:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a table title based on macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defining-a-table-title-based-on-macro-parameter/m-p/797815#M313679</link>
      <description>&lt;P&gt;Dear PaigeMiller&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;I was not aware of the fact that I also needed a "%end" there. So, what was lacking was because of ignorance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding your second point, I want to include some additional text and not just the "&amp;amp;Sex." part. In the actual data what I want to specificy is that the statistics I am summarizing are based on different age group restrictions depending on the (disease) subgroup of the population. Therefore, I would like to be able to some how write this out.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Feb 2022 14:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defining-a-table-title-based-on-macro-parameter/m-p/797815#M313679</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2022-02-22T14:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a table title based on macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defining-a-table-title-based-on-macro-parameter/m-p/797816#M313680</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/388382"&gt;@mgrasmussen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All of which brings up the interesting, and extremely important question: why would you use a macro at all here? Why don't you just use a BY statement in PROC MEANS? This is probably the easiest way to do this. Splitting data sets up using macros or macro variables is usually a poor choice when BY processing is possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=class;
    by sex;
run;

options nobyline;
ods noproctitle;
title "Table of #byval1";
proc means data=class;
    var age;
    by sex;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Feb 2022 14:09:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defining-a-table-title-based-on-macro-parameter/m-p/797816#M313680</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-02-22T14:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a table title based on macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defining-a-table-title-based-on-macro-parameter/m-p/797817#M313681</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/388382"&gt;@mgrasmussen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Regarding your second point, I want to include some additional text and not just the "&amp;amp;Sex." part. In the actual data what I want to specificy is that the statistics I am summarizing are based on different age group restrictions depending on the (disease) subgroup of the population. Therefore, I would like to be able to some how write this out.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Be specific. Show us an actual example (or even a made up example) of what you are talking about here. Don't start us off with a problem that isn't really what you are trying to do, because obviously solving that original problem hasn't helped you.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Feb 2022 14:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defining-a-table-title-based-on-macro-parameter/m-p/797817#M313681</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-02-22T14:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a table title based on macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defining-a-table-title-based-on-macro-parameter/m-p/797818#M313682</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/388382"&gt;@mgrasmussen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was not aware of the fact that I also needed a "%end" there. So, what was lacking was because of ignorance.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Every %DO has to have an associated %END;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Feb 2022 14:13:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defining-a-table-title-based-on-macro-parameter/m-p/797818#M313682</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-02-22T14:13:04Z</dc:date>
    </item>
  </channel>
</rss>

