*
;

/*
From: Ismail Parsa 
Reply-To: Ismail Parsa 
Newsgroups: comp.soft-sys.sas
Subject: Re: Error Trapping
Date: Tue, 24 Oct 1995 17:20:37 EST
Message-ID: <9510242220.AA03884@dragon.epsilon.com>

|>  From: "30747::STRICKLA"  writes
|>  Subject:      Error Trapping
|>  Problem:
|>  I want to have the system display a warning frame when one of the following
|>  conditions occurs:
|>  0 data records in a data step.
|>  Error in standard SAS code processing.
|>  SCL code error.
|>  What's the best way to trap these types of errors.  System variables,
|>  functions?

%check macro is my swiss army knife.
  I use it to check the existance of aSAS data set and the existance
  of character variables.  It could alsobe used to check the existance
  of a valid records in a SAS data set throughthe use of _N_ or
  the obs= data set option...

*-----------------------------*
|        Ismail Parsa         |
|   Epsilon Data Management   |
|     50 Cambridge Street     |
|   Burlington MA 01803 USA   |
|                             |
| E-MAIL: sip@epsilon.com     |
| V-MAIL: (617) 273-0250*6734 |
|    FAX: (617) 272-8604      |
|                             |
|  The Usual Caveat Applies   |
*-----------------------------*/
       /*-------*
        | Check |
        *-------*/
       %macro check( DATA ) ;
              %global exist ;
              %if &DATA ne %then
              %str(                    data _null_ ;
                         if 0 then set &DATA ;
                         stop ;
                    run ;                  ) ;
              %if &syserr = 0 %then %let exist = YES ;
                              %else %let exist = NO  ;
       %mend check ;

/*     %check ( mydata ) ;

       %if &exist = YES %then       %do ;
             ....
             .....
                           %end ;  */

*Similarly for the existance of character variables;

       /*-----------------*
        | Check Character |
        *-----------------*/
       %macro checkchr ( DATA ) ;
              %global existchr ;
              %if &DATA ne %then
              %str(                    data _NULL_ ;
                         if 0 then set &DATA ;
                         array _chrs_ (*) _character_ ;
                         _nchr_ = dim ( _chrs_ ) ;
                         call symput ( "_NCHR_", left(put(_nchr_,best.)) ) ;
                         stop ;
                    run ;
                  ) ;
              %if &_NCHR_ ne 0 %then %let existchr = YES ;
                               %else %let existchr = NO  ;
       %mend checkchr ;

*
;