X-Delivery-Notice:  SMTP MAIL FROM does not correspond to sender.
Return-Path: rjf2@PHPDLS1.EM.CDC.GOV
Encoding: 130 TEXT
X-Mailer: Microsoft Mail V3.0 (beta-2)
Newsgroups: bit.listserv.sas-l
Date:         Thu, 8 Oct 1992 10:07:00 EST
Reply-To:     rjf2@PHPDLS1.EM.CDC.GOV
From:         rjf2@PHPDLS1.EM.CDC.GOV
Subject:      macro for use with obs=0

content      : Response to handling programs with SSD where obs=0
summary      : macro supplied which checks #/obs and jumps to end of
               of program when obs=0
rlse/platform: V6.07 / MVS
Ron Fehd     :                SMTP:BitNet:    <rjf2@phpdls1.em.cdc.gov>
              Centers for Disease Control
              1600 Clifton Rd  MS:G25         FAX  : 404/639-1778
              Atlanta, GA 30333  USA          phone: 404/639-1707

Below is code for a macro, NMBR_OBS, which I use regularly in batch
processing programs. I process data for state subsets, and when the
particular state has no data for a particular SSD then I need a routine that
will not shut down further SAS processing of the rest of the states.


 /*RJF2.SAS.MACROS(NMBR#OBS) 90SEP19 -----------------------------------
MACRO NMBR_OBS returns macro-var with user-supplied name, which contains
  value of number of observations in most recently created SSD.
For optimizing, pass name of any variable in the most recently created
  dataset to reduce the time taken by proc CONTENTS.
USAGE:
DATA;X1=1;
%NMBR_OBS(N);
or
%NMBR_OBS(N,_ANY_VAR=X1);
can be used in a macro to test if an SSD has any observations.
if none, then print message and %goto end of processing of macro:

%MACRO PROCESS;*example usage******************************************;

DATA;
  set SOMETHING;

%NMBR_OBS(N);

%IF not &N %THEN %DO; DATA _NULL_;
                        put 'No Observations in SSD.';
                      %GOTO ENDOSTEP;
                                                                   %END;
more SAS statements;
%ENDOSTEP: run;***************************************PROCESS ***;%MEND;
........................................................................
RJF2 added trace msg at exit                                     91Nov12
RJF2 data =        : (keep = &_ANY_VAR),
     out = CONTENTS: (keep = Nobs),
     set   CONTENTS: (obs  = 1)                                  92May04
........................................................comments: end */


%MACRO NMBR_OBS(_MAC_VAR,_ANY_VAR=);/*--------------------------------*/

proc CONTENTS                      data =
  %IF       &SYSVER le 5.18 %THEN         _LAST_   ;
  %ELSE %IF &SYSVER ge 6.06 %THEN         &SYSLAST.;
  %IF &_ANY_VAR ne %THEN                            (keep = &_ANY_VAR.);
                                   out  = CONTENTS  (keep = Nobs)
                                   noprint;
%GLOBAL &_MAC_VAR.;

DATA _NULL_;
  set CONTENTS (obs=1);
  call symput("&_MAC_VAR.",left(put(Nobs,best12.)));

run;
%put @@macro NMBR_OBS exit, returns: "&_MAC_VAR" == <&&&_MAC_VAR>;
 /*....................................................*NMBR_OBS*/%MEND;

 /*further testing******************************************************
DATA;
%MACRO DO_THIS;
%DO I = 1 %TO 1000 ; X&I=1;
                     output;                                       %END;
                                                                  %MEND;
%DO_THIS;
*proc PRINT;
*%NMBR_OBS(N);
%NMBR_OBS(N,_ANY_VAR=X1);

*PUT #obs in DATA: <<&N>>;
*PUT SYSVER == &SYSVER.     ;
************************************************************************/
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU