BookmarkSubscribeRSS Feed
PJ007
Calcite | Level 5

Hi all!
I need the following type1file macro to trigger an email when the proc import fails.
It works, but it is not working when it is being called from the ' Import' macro.
Any help would be greatly appreaciated as I am really struggling with this.

Thanks!

%macro track_err;
%global err_status;
%let err_status = %sysfunc(max(&err_status, &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 &err_status;

data _null_;
if &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:&nm.";
put " ";
put "Thank you.";
put " ";

abort abend;
end; 
run;

%MEND Type2File;


%MACRO Import;
%do I=1 %to &totobs. ;
data _null_; 
set directory_summary;
If obs=&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;
3 REPLIES 3
cau83
Pyrite | Level 9

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?

PJ007
Calcite | Level 5

Thank you for your response. It works when outside the macro and in a data step.

I think the reason it is failing is because the &syserr variable is resolving to 0. I tried syserr and sysrc. 

None of them seem to work when called within the Import macro. 

PJ007
Calcite | Level 5

I need the code to abort if the proc import fails. 

I tried something as simple as this instead of the email. That doesnt seem to work either within the Import macro call: 

data _null_;
if &syserr>0 then do;
put 'The import was unsucessful. Please correct the errors in the file and reload.';
abort abend;
end;
run;


SYMBOLGEN: Macro variable SYSERR resolves to 0

Even if the proc import failed, both syserr and sysrc are resolving to zero. 

From the log: 

data _null_; if 0>0 then do; put 'The import was unsucessful. Please correct the
errors in the file and reload.'; abort abend; end; run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 802 views
  • 0 likes
  • 2 in conversation