BookmarkSubscribeRSS Feed
titan31
Quartz | Level 8

Hi,

 

I want to run to abort a DI job on certain errors. I'm reading files stored in a location, and if the file doesn't exist, I'd like to abort the job and not run further steps. . I've got the aborting working for any errors encountered, but is there anyway to restrict it to just abort if it sees, ERROR: Physical file does not exist. I'm using the Return Code Check transformation to status handle the file reader, so if there's anyways to do it throug that, it'd be preferable than through BASE SAS. 

 

Thanks

3 REPLIES 3
collinelliot
Barite | Level 11

I'm not sure about the mechanism to abort, but you could use code to check for the existence of a file (which is the error you're getting) and then conditionally execute other code inside a macro only if the file is found. Some code I've used is shown below.

 

%macro check_for_file(dir); 

   %local rc fileref;
   %global file_found_flag;
   %let rc = %sysfunc(filename(fileref, &dir));
   %put Checking for existence of &dir;
   %if %sysfunc(fexist(&fileref))  %then %let file_found_flag=1;    
   %else %let file_found_flag=0;

%mend check_for_file;

%macro x(file);

%check_for_file(&file)

%if &file_found_flag = 1 %then %do;

%put The file exists. Run code...;

%end;
%else %do;

    %put The file was not found.;

%end;
%mend x;
%x(yourPath\yourFile)
LinusH
Tourmaline | Level 20
The functionality you're asking for is standard in most scheduling software. Use that, and shouldn't need to handle this in SAS at all.
Data never sleeps
SASKiwi
PROC Star

I prefer using general SAS options for SAS error checking and / or scheduler options as they are a lot easier and cope with most problems. The one I find most useful is the SAS option SYNTAXCHECK:

 

http://support.sas.com/documentation/cdl/en/lesysoptsref/69799/HTML/default/viewer.htm#n014qbvh3po8w...

 

With this option whenever SAS hits a significant error it goes into syntax check mode and doesn't process any data.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1049 views
  • 2 likes
  • 4 in conversation