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?
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
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
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?
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
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).
%RETURN;
wouldn't be able to work ?
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.
Thanks for sharing, DN. Strong and flexible.
Haikuo
May want to see if ENDSAS or BYE works.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.