<?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: Rationalize the length of a macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Rationalize-the-length-of-a-macro/m-p/984783#M43730</link>
    <description>&lt;P&gt;I am not sure I understand what the question is.&amp;nbsp; If you want to run the same code afterwards just place it beyond the second %END.&amp;nbsp; That way you do not have two copies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you could simplify the current code by using the macro logic to set macro variables that you use to generate the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro freq_for_value(data=, variable=, filter_value=);
  %local where ;
  %if %length(&amp;amp;filter_value.)  %then %do;
     %let where=where=(&amp;amp;variable. = "&amp;amp;filter_value.");
title "Frequency for &amp;amp;variable. with value &amp;amp;filter_value.";
  %end;
  %else %do;
title "Frequency for all values of &amp;amp;variable.";
  %end;

proc freq data=&amp;amp;data. (&amp;amp;where);
  tables &amp;amp;variable.;
run;

/* Other code goes here */

%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 14 Mar 2026 15:14:08 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2026-03-14T15:14:08Z</dc:date>
    <item>
      <title>Rationalize the length of a macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rationalize-the-length-of-a-macro/m-p/984782#M43729</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following piece of code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro freq_for_value(data=, variable=, filter_value=);

    %if &amp;amp;filter_value. ne %str() %then %do;
        proc freq data=&amp;amp;data. (where=(&amp;amp;variable. = "&amp;amp;filter_value."));
            tables &amp;amp;variable.;
            title "Frequency for &amp;amp;variable. with value &amp;amp;filter_value.";
        run;
    %end;
    %else %do;
        proc freq data=&amp;amp;data.;
            tables &amp;amp;variable.;
            title "Frequency for all values of &amp;amp;variable.";
        run;
    %end;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This macro basically performs proc freq in two different conditions: 1) if a variable takes a specific value and 2) if not.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to run this macro but I have many lines of code after the first proc freq that I have to repeat (and that are identical) after the second proc freq like for example the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro freq_for_value(data=, variable=, filter_value=);

    %if &amp;amp;filter_value. ne %str() %then %do;
        proc freq data=&amp;amp;data. (where=(&amp;amp;variable. = "&amp;amp;filter_value."));
            tables &amp;amp;variable.;
            title "Frequency for &amp;amp;variable. with value &amp;amp;filter_value.";
        run;
        /*I add 10 rows of output formatting*/   
      ............................................................................................
      .............................................................................................
      ..............................................................................................

    %end;
    %else %do;
        /* If no filter value, run PROC FREQ on the entire data set */
        proc freq data=&amp;amp;data.;
            tables &amp;amp;variable.;
            title "Frequency for all values of &amp;amp;variable.";
        run;
    %end;
 /*I add 10 rows of output formatting*/   
      ............................................................................................
      .............................................................................................
      ..............................................................................................

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way or a condition that could be declared at the beginning in order to prevent to repeat the coding after proc freq (output formatting) that would make the macro unnecessarily long and redundant? In other words I'm referring to something that, based on the fact that the variable can or not take a specified value, performs proc freq in a way or in the other one.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Mar 2026 14:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rationalize-the-length-of-a-macro/m-p/984782#M43729</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2026-03-14T14:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Rationalize the length of a macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rationalize-the-length-of-a-macro/m-p/984783#M43730</link>
      <description>&lt;P&gt;I am not sure I understand what the question is.&amp;nbsp; If you want to run the same code afterwards just place it beyond the second %END.&amp;nbsp; That way you do not have two copies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you could simplify the current code by using the macro logic to set macro variables that you use to generate the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro freq_for_value(data=, variable=, filter_value=);
  %local where ;
  %if %length(&amp;amp;filter_value.)  %then %do;
     %let where=where=(&amp;amp;variable. = "&amp;amp;filter_value.");
title "Frequency for &amp;amp;variable. with value &amp;amp;filter_value.";
  %end;
  %else %do;
title "Frequency for all values of &amp;amp;variable.";
  %end;

proc freq data=&amp;amp;data. (&amp;amp;where);
  tables &amp;amp;variable.;
run;

/* Other code goes here */

%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Mar 2026 15:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rationalize-the-length-of-a-macro/m-p/984783#M43730</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-03-14T15:14:08Z</dc:date>
    </item>
  </channel>
</rss>

