<?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: Trigger email on proc import in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Trigger-email-on-proc-import/m-p/487082#M126849</link>
    <description>&lt;P&gt;I need the code to abort if the proc import fails.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried something as simple as this instead of the email. That doesnt seem to work either within the Import macro call:&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;if &amp;amp;syserr&amp;gt;0 then do;&lt;BR /&gt;put 'The import was unsucessful. Please correct the errors in the file and reload.';&lt;BR /&gt;abort abend;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;SYMBOLGEN: Macro variable SYSERR resolves to 0&lt;/P&gt;&lt;P&gt;Even if the proc import failed, both syserr and sysrc are resolving to zero.&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the log:&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_; if 0&amp;gt;0 then do; put 'The import was unsucessful. Please correct the&lt;BR /&gt;errors in the file and reload.'; abort abend; end; run;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Aug 2018 17:30:24 GMT</pubDate>
    <dc:creator>PJ007</dc:creator>
    <dc:date>2018-08-15T17:30:24Z</dc:date>
    <item>
      <title>Trigger email on proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trigger-email-on-proc-import/m-p/487055#M126833</link>
      <description>&lt;P&gt;Hi all!&lt;BR /&gt;I need the following type1file macro to trigger an email when the proc import fails.&lt;BR /&gt;It works, but it is not working when it is being called from the ' Import' macro.&lt;BR /&gt;Any help would be greatly appreaciated as I am really struggling with this.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro track_err;
%global err_status;
%let err_status = %sysfunc(max(&amp;amp;err_status, &amp;amp;syserr ne 0));
%mend;



%MACRO Type2File;

%let err_status = 0; 
PROC IMPORT OUT= Type1File DATAFILE= "Filename.xls"
DBMS=xls REPLACE;
SHEET="Sheet1"; 
GETNAMES=YES;
RUN;

%track_err;

%put &amp;amp;err_status;

data _null_;
if &amp;amp;err_status=1 then do;
filename imptfail EMAIL
to="abc@abc.com"
from="cdde@cdde.com"
subject="Import Failure"
importance="HIGH";
file imptfail;
put "Hi,";
put " ";
put "The import was unsuccessful. Please correct the errors in the file and reload.";
put "Further processing of this file would be stopped until we receive a new file.";
put "Name of the file with error:&amp;amp;nm.";
put " ";
put "Thank you.";
put " ";

abort abend;
end; 
run;

%MEND Type2File;


%MACRO Import;
%do I=1 %to &amp;amp;totobs. ;
data _null_; 
set directory_summary;
If obs=&amp;amp;i. ;

call symput('fn',"\\filepathfiles\"||trim(filename)) ;
call symput('nm',trim(filename)) ;

IF filetype=".csv" and index(upcase(filename), "ABC") THEN call execute ('%Type1File') ;
ELSE IF filetype=".xls" and index(upcase(filename), "CDE") THEN call execute ('%Type2File');
ELSE IF filetype=".xls" and index(upcase(filename), "FGH") THEN call execute ('%Type3File') ;


run;

%sysExec move "Filepath1" "Filepath2";

%end;
%MEND Import;
%Import;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Aug 2018 16:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trigger-email-on-proc-import/m-p/487055#M126833</guid>
      <dc:creator>PJ007</dc:creator>
      <dc:date>2018-08-15T16:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger email on proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trigger-email-on-proc-import/m-p/487056#M126834</link>
      <description>&lt;P&gt;Does it work in the DATA STEP / call execute without being in the import macro? Have you tried adding a put statement or something else so that you know whether your conditional execution is resolving the way you think it would?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Aug 2018 16:16:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trigger-email-on-proc-import/m-p/487056#M126834</guid>
      <dc:creator>cau83</dc:creator>
      <dc:date>2018-08-15T16:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger email on proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trigger-email-on-proc-import/m-p/487076#M126845</link>
      <description>&lt;P&gt;Thank you for your response. It works when outside the macro and in a data step.&lt;/P&gt;&lt;P&gt;I think the reason it is failing is because the &amp;amp;syserr variable is resolving to 0. I tried syserr and sysrc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;None of them seem to work when called within the Import macro.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Aug 2018 17:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trigger-email-on-proc-import/m-p/487076#M126845</guid>
      <dc:creator>PJ007</dc:creator>
      <dc:date>2018-08-15T17:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger email on proc import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trigger-email-on-proc-import/m-p/487082#M126849</link>
      <description>&lt;P&gt;I need the code to abort if the proc import fails.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried something as simple as this instead of the email. That doesnt seem to work either within the Import macro call:&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;if &amp;amp;syserr&amp;gt;0 then do;&lt;BR /&gt;put 'The import was unsucessful. Please correct the errors in the file and reload.';&lt;BR /&gt;abort abend;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;SYMBOLGEN: Macro variable SYSERR resolves to 0&lt;/P&gt;&lt;P&gt;Even if the proc import failed, both syserr and sysrc are resolving to zero.&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the log:&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_; if 0&amp;gt;0 then do; put 'The import was unsucessful. Please correct the&lt;BR /&gt;errors in the file and reload.'; abort abend; end; run;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Aug 2018 17:30:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trigger-email-on-proc-import/m-p/487082#M126849</guid>
      <dc:creator>PJ007</dc:creator>
      <dc:date>2018-08-15T17:30:24Z</dc:date>
    </item>
  </channel>
</rss>

