I'm trying to send RC=255 to JES when all 3 files are empty. The program sends RC=0 to JES.
DATA _NULL_;
SET OT.XXXX OT.YYYY OT.ZZZZ;
IF _N_ = 0 THEN ABORT 255;
RUN;
Thanks! Les
I would try (untested):
DATA _NULL_;
IF _N_ = 1 and last THEN ABORT 255;
SET OT.XXXX OT.YYYY OT.ZZZZ end=last;
RUN;
When the step compiles, it will set the variable last to 1 if all datasets on the SET statement have 0 obs.
Note: _N_ is not a counter of the number of records, it's a counter of the number of DATA step iterations. _N_ can never be 0.
You need the PUT statement before the SET statement, because the step will stop when the SET statement executes if there are 0 records to read.
Pretend you are SAS and you have to run your data step.
DATA _NULL_;
SET OT.XXXX OT.YYYY OT.ZZZZ;
IF _N_ = 0 THEN ABORT 255;
RUN;
First instruction you get to is the SET statement. When there are zero observations in all three of those input datasets what do you think SAS is going to do in that case?
Try adding some PUT statements to see what is happening.
DATA _NULL_;
put 'BEFORE SET STATEMENT. ' _n_= ;
SET OT.XXXX OT.YYYY OT.ZZZZ;
put 'AFTER SET STATEMENT.' _n_=;
IF _N_ = 0 THEN ABORT 255;
put 'AFTER IF STATEMENT. ' _n_=;
RUN;
If you want to use a data step to detect number of observations then you need to use either END= or NOBS= options of the SET statement to specify the name of the temporary variable to use for that information. You can then test that variable's value BEFORE the SET statement stops the data step.
You could use the boolean flag created by the END= option.
DATA _NULL_;
IF EOF THEN ABORT 255;
STOP;
SET OT.XXXX OT.YYYY OT.ZZZZ END=EOF;
RUN;
Or the integer value created by the NOBS= option.
DATA _NULL_;
IF NOBS=0 THEN ABORT 255;
STOP;
SET OT.XXXX OT.YYYY OT.ZZZZ NOBS=NOBS;
RUN;
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.