<?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: Create macro variable based off of table values in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Create-macro-variable-based-off-of-table-values/m-p/514257#M2695</link>
    <description>&lt;P&gt;First you need to understand the relationship between the macro pre-processor and actual SAS code.&lt;/P&gt;
&lt;P&gt;You use macro code to generate SAS code. Once SAS sees a full step it runs it.&lt;/P&gt;
&lt;P&gt;So you ran these statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let tomail=No Errors No Warning;
%let tomail=Warning found;
%let tomail=Error found ;

data _null_;
   set noerr;
   if substr(alert,1,4)='NOTE' then do;
   end;
   if substr(alert,1,5)='WARNI' then do;
   end;
   if substr(alert,1,5)='ERROR' then do;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Second it looks like your sample data has multiple observations, but you are generating only one macro variable.&amp;nbsp; So you need to have logic that reflects that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set noerr end=eof;
  if alert=:'WARNI' then warnings+1;
  if alert=:'ERROR' then errors+1;
  if eof then do;
    if errors then call symputx('tomail','Errors found');
    else if warnings then call symputx('tomail','Warnings found');
    else call symputx('tomail','No Errors or Warnings');
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 18 Nov 2018 16:40:38 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-11-18T16:40:38Z</dc:date>
    <item>
      <title>Create macro variable based off of table values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-macro-variable-based-off-of-table-values/m-p/514253#M2694</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;i am trying to create a macro variable based of the value in table, but my macros are wrongly assigned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table noerr&lt;BR /&gt;alert&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; count&lt;BR /&gt;Note&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;BR /&gt;Warni&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;BR /&gt;&lt;BR /&gt;table err&lt;BR /&gt;alert&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;count&lt;BR /&gt;Note&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;BR /&gt;Error&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;BR /&gt;Warni&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro gen;&lt;BR /&gt;data _null_;&lt;BR /&gt;set noerr;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if substr(alert,1,4)='NOTE' then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let tomail=No Errors No Warning;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if substr(alert,1,5)='WARNI' then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %let tomail=Warning found;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if substr(alert,1,5)='ERROR' then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %let tomail=Error found ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;%gen;&lt;BR /&gt;%put &amp;amp;=tomail;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.what i want?&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;a.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if&amp;nbsp; alert=error&amp;nbsp; &amp;nbsp; &amp;nbsp;then a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;macro variable&amp;nbsp; &amp;nbsp;'tomail'&amp;nbsp; &amp;nbsp;should be created resolving to&amp;nbsp; &amp;nbsp; &amp;nbsp;'error found'.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;( if there is 'Error' ,there is no need to assign or resolve for latter two)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;b.else if&amp;nbsp; alert=warni&amp;nbsp; &amp;nbsp; then a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;macro variable&amp;nbsp; &amp;nbsp;&lt;SPAN&gt;'tomail'&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;should be created resolving to&amp;nbsp; &amp;nbsp; &amp;nbsp;'Warning found'.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;c.else if&amp;nbsp; alert=note&amp;nbsp; &amp;nbsp; &amp;nbsp;then a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; macro&amp;nbsp;variable&amp;nbsp; &amp;nbsp;&lt;SPAN&gt;'tomail'&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;should be created resolving to&amp;nbsp; &amp;nbsp; &amp;nbsp;'No error found'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please suggest.&lt;/P&gt;&lt;P&gt;Thank You,&lt;/P&gt;</description>
      <pubDate>Sun, 18 Nov 2018 16:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-macro-variable-based-off-of-table-values/m-p/514253#M2694</guid>
      <dc:creator>himalayancat</dc:creator>
      <dc:date>2018-11-18T16:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variable based off of table values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-macro-variable-based-off-of-table-values/m-p/514257#M2695</link>
      <description>&lt;P&gt;First you need to understand the relationship between the macro pre-processor and actual SAS code.&lt;/P&gt;
&lt;P&gt;You use macro code to generate SAS code. Once SAS sees a full step it runs it.&lt;/P&gt;
&lt;P&gt;So you ran these statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let tomail=No Errors No Warning;
%let tomail=Warning found;
%let tomail=Error found ;

data _null_;
   set noerr;
   if substr(alert,1,4)='NOTE' then do;
   end;
   if substr(alert,1,5)='WARNI' then do;
   end;
   if substr(alert,1,5)='ERROR' then do;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Second it looks like your sample data has multiple observations, but you are generating only one macro variable.&amp;nbsp; So you need to have logic that reflects that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set noerr end=eof;
  if alert=:'WARNI' then warnings+1;
  if alert=:'ERROR' then errors+1;
  if eof then do;
    if errors then call symputx('tomail','Errors found');
    else if warnings then call symputx('tomail','Warnings found');
    else call symputx('tomail','No Errors or Warnings');
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Nov 2018 16:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-macro-variable-based-off-of-table-values/m-p/514257#M2695</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-18T16:40:38Z</dc:date>
    </item>
  </channel>
</rss>

