Hi
My SAS code has mutliple data step and proc steps. I want end the sas session when certain condition met.
I am running my sas code on UNIX in batch mode. When certain dataset has 0 observations, I want to end session. I used following is example code, it's not working as I expected.
..multiple sas data, proc steps
data _null_;
set old_dataset nobs=_nobs;
if _nobs=0 then call system('endsas');
run;
..multiple data steps.
Thank you
You need to test NOBS before the SET statement executes. Otherwise the data step stops as soon as the SET statement tries to read past the end of the file.
data _null_;
if _nobs=0 then call system('endsas');
else stop;
set old_dataset nobs=_nobs;
run;
Than you for reply. I modified the code and ran the batch job. The sas session not terminating, still continue to process further sas steps. am I missing to add anything? endsas is not terminating session here.
Did you remember to include the semi-colon for the ENDSAS statement in the CALL EXECUTE() call?
Statements endsas and errorabend are doable in batch, developping in Eguide (and others) it is a bad approach. https://communities.sas.com/message/148347 see CH
In structures programming it is better to validate all conditions at the first steps. Than only whan all input is valid to proceed
With a bathc approach don't make the program too big. smaller pieces are easily connected. Restarting / recovering will become more easy.
call system runs a system process, in this case it will try to run the program endsas if such is found in your search path.
I guess you want to use call execute, but why go to such a hassle?
if _nobs = 0 then abort abend 4;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.