<?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: How to include macro variable in an email in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-include-macro-variable-in-an-email/m-p/875094#M345763</link>
    <description>&lt;P&gt;Your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;		put "&amp;amp;test";
		PUT "The following tables are empty";
		put &amp;amp;empty_tables;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the difference between the first line I quoted above, and the last line I quoted above? If you can answer that, I think you can fix your code yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, please heed &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 2&lt;/A&gt; — read the log, which clearly would indicate you have done something wrong.&lt;/P&gt;</description>
    <pubDate>Wed, 10 May 2023 21:36:42 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-05-10T21:36:42Z</dc:date>
    <item>
      <title>How to include macro variable in an email</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-include-macro-variable-in-an-email/m-p/875058#M345743</link>
      <description>&lt;P&gt;I've created a macro that creates a macro variable containing the names of tables with 0 observations. Within this macro, I also send an email if any tables are empty/have 0 observations. For some reason, the value of the macro variable containing name of empty tables isn't being included in my email. The email is sent, but the macro var's value isn't included in the email. What am I doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Reprex with notes/comments below:&lt;/P&gt;&lt;PRE&gt;/*include names of tables to check*/
%let tables = a b c;

/*the corresponding row counts for the tables in &amp;amp;tables*/
%let table_row_counts = 0 100 500;

%let number_of_tables = %sysfunc(countw(&amp;amp;tables));

/*Check each table's row counts, if any table has 0 rows, then include table name in &amp;amp;empty_tables*/
%macro validate();

        /*Test macro -- this is sucessfully included in email*/
	%let test = test message;

	%let empty_tables = ;

	%do i = 1 %to &amp;amp;number_of_tables;
		%if %scan(&amp;amp;table_row_counts,&amp;amp;i) = 0 %then %do;
			%let empty_tables = %scan(&amp;amp;tables,&amp;amp;i) &amp;amp;empty_tables;
		%end;
	%end; 

	%let total_empty_tables = %sysfunc(countw(&amp;amp;tables));
	%put &amp;amp;empty_tables; /*Resolves to "a" here, but is missing in email sent below*/

	%if &amp;amp;total_empty_tables &amp;gt; 0 %then %do;
		* Email saying module has failed;
		FILENAME Mailbox EMAIL ('your_email@email.com')
		Subject='Empty Table Alert';
		DATA _NULL_;
		FILE Mailbox;
		put "&amp;amp;test";
		PUT "The following tables are empty";
		put &amp;amp;empty_tables;
		RUN;
	%return;
	%end;
%mend;
%validate();&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 May 2023 21:00:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-include-macro-variable-in-an-email/m-p/875058#M345743</guid>
      <dc:creator>everyone</dc:creator>
      <dc:date>2023-05-10T21:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to include macro variable in an email</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-include-macro-variable-in-an-email/m-p/875077#M345751</link>
      <description>Just a quick guess...but should it be %put since you are evaluating the macro variable in your email message?&lt;BR /&gt;&lt;BR /&gt;/*revised line at bottom of your code*/&lt;BR /&gt;%put &amp;amp;empty_tables;&lt;BR /&gt;</description>
      <pubDate>Wed, 10 May 2023 20:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-include-macro-variable-in-an-email/m-p/875077#M345751</guid>
      <dc:creator>svh</dc:creator>
      <dc:date>2023-05-10T20:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to include macro variable in an email</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-include-macro-variable-in-an-email/m-p/875094#M345763</link>
      <description>&lt;P&gt;Your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;		put "&amp;amp;test";
		PUT "The following tables are empty";
		put &amp;amp;empty_tables;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the difference between the first line I quoted above, and the last line I quoted above? If you can answer that, I think you can fix your code yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, please heed &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 2&lt;/A&gt; — read the log, which clearly would indicate you have done something wrong.&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 21:36:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-include-macro-variable-in-an-email/m-p/875094#M345763</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-10T21:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to include macro variable in an email</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-include-macro-variable-in-an-email/m-p/875096#M345765</link>
      <description>You ticked the "no solution needed for this topic" when you created the post. Is that accurate? If not, you can click the three lines beside the post to edit it and remove that option.</description>
      <pubDate>Wed, 10 May 2023 21:43:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-include-macro-variable-in-an-email/m-p/875096#M345765</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-10T21:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to include macro variable in an email</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-include-macro-variable-in-an-email/m-p/875097#M345766</link>
      <description>&lt;P&gt;Let's reduce the complexity of the code for clarity:&lt;/P&gt;
&lt;PRE&gt;%let empty_tables=a;

data _null_;&lt;BR /&gt;
   put &amp;amp;empty_tables.;
run;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;233  %let empty_tables=a;
234
235  data _null_;
236
237     put &amp;amp;empty_tables.;
238  run;

NOTE: Variable a is uninitialized.
&lt;/PRE&gt;
&lt;P&gt;The PUT statement resolves to :&amp;nbsp; put a;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which is used in a manner that SAS thinks is a variable.&lt;/P&gt;
&lt;P&gt;You want quotes around your macro variable so it is treated as a text value that Put understands.&lt;/P&gt;
&lt;PRE&gt;239  %let empty_tables=a;
240
241  data _null_;
242
243     put "&amp;amp;empty_tables.";
244  run;

a

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 21:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-include-macro-variable-in-an-email/m-p/875097#M345766</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-10T21:45:49Z</dc:date>
    </item>
  </channel>
</rss>

