 %MACRO R03EDIT1(AGE=, SEX=, ICD9= );
 %**********************************************************************
 ***********************************************************************
 1 MACRO NAME:  R03EDIT1
 2 PURPOSE:     age/sex edits on ICD9 - are based on MCE list to check
                if age or sex for a beneficiary is within the
                range of acceptable age/sex, if not- RXCC is set to 
                -1.0 - invalid
 3 PARAMETERS:  AGE   - beneficiary age variable calculated by DOB
                        from a person level file
                SEX   - beneficiary SEX variable in a person level file
                ICD9  - diagnosis variable in a diagnosis file

 4 COMMENTS:    1. Age format AGEFMT and sex format SEXFMT are 
                   parameters in the main macro. They have to correspond
                   to the years of data

                2. If ICD9 code does not have any restriction on age
                   or sex then the corresponding format puts it in "-1"

                3. AGEL format sets lower limits for age
                   AGEU format sets upper limit for age
                   for specific edit categories:
                   "0"= "0 newborn (age 0)      "
                   "1"= "1 pediatric (age 0 -17)"
                   "2"= "2 maternity (age 12-55)"
                   "3"= "3 adult (age 14+)      "

                4. SEDITS - parameter for the main macro
 **********************************************************************;

  %* CME edits if needed (should be decided by a user by setting
     parameter SEDITS);
  %IF &SEDITS = 1 %THEN %DO;
     %* check if Age is within acceptable range;
     _TAGE=PUT(&ICD9, $&AGEFMT..);
     IF _TAGE NE "-1" AND
        (&AGE < INPUT(PUT(_TAGE, $AGEL.),8.) OR
         &AGE > INPUT(PUT(_TAGE, $AGEU.),8.)) THEN RXCC='-1.0';

     %* check if Sex for a person is the one in the MCE file;
     _TSEX=PUT(&ICD9, $&SEXFMT..);
     IF _TSEX NE "-1"  & _TSEX NE &SEX THEN RXCC='-1.0';

  %END;
 %MEND R03EDIT1;
