1

I have developed a SAS process in Enterprise Guide 7.1 that sends e-mails daily (if need be).

The way it works is this: [external program] generates a file which specifies who needs to be emailed and the subject matter . My sas process then looks like this: 1. import this file. 2. manipulate this file. 3. generate emails based on contents of manipulated file.

The problem is, everything crashes if the original file imported in step 1 is empty. Is there a way to run the import, check if the dataset is empty, and then if it is terminate the entire sas process tree?

Thank you in advance, I've been searching but to no avail.

Jesse_m_m
  • 185
  • 1
  • 9

2 Answers2

0

Best way would be to put step 2 and 3 completely in a macro and only execute it when step1 dataset is not empty.

step 1 import file in dataset mydata

data _null_;
set mydata nobs=number;
call symput('mydata_count', number);
stop;
run;


%macro m;
%if &mydata_count > 0 %then %do;

step 2  manipulate this file

step 3 generate emails

%end;
%mend;

%m;

As alternative you could use the statements "Endsas" or "abort" which both terminate your job and session but they can have unwanted sideeffects, you can find these statements and information about them easily when googling for them together with keyword sas.

Although the two statements do what you originally wanted, i would recommend the logical approach i posted as first, because you have more control about what is happening that way and you can avoid some bad side-effects when working with the statements

kl78
  • 1,628
  • 1
  • 16
  • 26
0

IMO a better way is to start using a macro like %runquit;. See my answer here. https://stackoverflow.com/a/31390442/214994

Basically instead of using run; or quit; at the end of a step you use %runquit;. If any errors occurred during that step then the rest of the SAS process will be aborted. If running in batch, the entire process is killed. If running interactively, code execution stops, but your interactive session remains open.

EDIT: This assumes you get some kind of error message or warning if the file is empty.

Community
  • 1
  • 1
Robert Penridge
  • 8,424
  • 2
  • 34
  • 55