BookmarkSubscribeRSS Feed
nbonda
Obsidian | Level 7

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

5 REPLIES 5
Tom
Super User Tom
Super User

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;

nbonda
Obsidian | Level 7

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.

Tom
Super User Tom
Super User

Did you remember to include the semi-colon for the ENDSAS statement in the CALL EXECUTE() call?

jakarman
Barite | Level 11

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.

---->-- ja karman --<-----
Kurt_Bremser
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2234 views
  • 1 like
  • 4 in conversation