BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
FrankE
Fluorite | Level 6

Hi guys,

I'm running SAS 9.3 on a Windows 2008R2 server and I have a 3rd party scheduler that runs my scheduled SAS jobs. 

I have a few SAS jobs that can periodically have no records in them so I conditionally create a report telling the user that there were no records found.  The issue comes when I need to end SAS after I create this "dummy" report. 

I've tried the "abort return 0" and "%abort return 0" statements but it appears that SAS is still returning a non 0 return code.  Is there any way to stop SAS from processing further without causing an error? 

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

Maybe something like this: you can play with obs=0/1 to see the different results:

%macro test;

data _1;

   set sashelp.class (obs=0);

run;

data _null_;

call symputx('nobs',nobs);

set _1 nobs=nobs;

  stop;

run;

%if &nobs=0 %then %do;

    %put SAS session is aborted error_rc=&syserr;

       

     %goto exit;

  %end;

  %put Normal SAS session continuned;

%exit:

%mend;

%test;

Haikuo

View solution in original post

8 REPLIES 8
Haikuo
Onyx | Level 15

More information is probably needed here. so I guess you use 'abort' to conditionally stop the batch process, and after doing that you are not happy that &syserr or &sqlrc is not zero.

I hate to break this to you, but if you choose to use 'abort', there is no way to trick SAS not to put an error on record somewhere. So my question gets down to this: Is it possible for you to wrap up your whole code in Macro, and whenever your 'abort' condition is met, you just leap out of Macro and stop the whole process without literally using 'abort' statement?

Haikuo

FrankE
Fluorite | Level 6

Yep you're correct.   Actually the code creating either the actual report or the 'dummy' empty report is already wrapped in a macro and it's always the last macro in the job.  So jumping out of the macro would work for me I think (?)  Can you point me to the statements I need to do that?

Haikuo
Onyx | Level 15

Maybe something like this: you can play with obs=0/1 to see the different results:

%macro test;

data _1;

   set sashelp.class (obs=0);

run;

data _null_;

call symputx('nobs',nobs);

set _1 nobs=nobs;

  stop;

run;

%if &nobs=0 %then %do;

    %put SAS session is aborted error_rc=&syserr;

       

     %goto exit;

  %end;

  %put Normal SAS session continuned;

%exit:

%mend;

%test;

Haikuo

FrankE
Fluorite | Level 6

Thanks very much for your help.  I used a combo of your suggestion and this paper (http://www.sascommunity.org/sugi/SUGI95/Sugi-95-73%20Tilanus.pdf).

Ksharp
Super User

%RETURN;

wouldn't be able to work ?

data_null__
Jade | Level 19

Maybe the macro processes a data set and there is some kind of subsetting option, an expression, that is passed to a WHERE statement.  And the macro creates a working copy of the data applying any observation or variable subsets required.  The condition we seek "Are there NONE?" can be checked when that data is created.

%macro main(data=sashelp.class,where=);
  
%local error_rc;  
  
%let error_rc = 0;
   data &sysmacroname._1;
      if _n_ eq
1 and eof then do;
         call symputX('error_rc',1,'local');
         put 'NOTE: Macro ending due to no observations returned from data.';
         stop;
         end;
      set &data end=eof;
      where &where;
      run;
  
%if &error_rc %then %do;
     
%put NOTE: Macro &sysmacroname aborted error_rc=&error_rc;
      %goto exit;
      %end;
  
%put NOTE: Normal SAS session continuned;

%exit:
   proc datasets library=work nolist;
      delete &sysmacroname._:;
      run;
      quit;
  
%put NOTE: Macro &sysmacroname ending.;
   %mend;

%
main(where=age eq 9);
%main(data=sashelp.shoes(obs=0));
Haikuo
Onyx | Level 15

Thanks for sharing, DN. Strong and flexible.

Haikuo

ballardw
Super User

May want to see if ENDSAS or BYE works.

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 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
  • 8 replies
  • 13187 views
  • 2 likes
  • 5 in conversation