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-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
  • 5 replies
  • 1909 views
  • 1 like
  • 4 in conversation