/****************************************************************************************

BrCa_RAM  SAS macro to project for absolute risk of BrCa based on the Gail Model


NCI BrCa Risk Assessment Macro (NCI BCRAM)  Version 3.01                         04/29/15

   Modify following lines of incorrect code  (lines 639-640):

      *** for asian-americans NR_Cat=2 is pooled with NR_Cat=1       *** pool # rel >=1;
      if (&Race ge 6 and &Race le 11 and NR_Cat eq 2) then NR_Cat=1; *** with # rel  =1;

   to:

      *** for asian-americans NR_Cat=2 is pooled with NR_Cat=1;      *** pool # rel >=2;
      if (&Race ge 6 and &Race le 11 and NR_Cat eq 2) then NR_Cat=1; *** with # rel  =1;

   Acknowledgements and thanks to Mr. Michael Stagner of IMS Inc. for noticing and
   pointing out this error.


NCI BrCa Risk Assessment Macro (NCI BCRAM)  Version 3.0                          12/05/12

   Includes the projection of absolute risk for an  "AVG woman" as in the NCI (B)reast
  (C)ancer (R)isk (A)ssessment (T)ool  ie  NCI BCRAT

   Note that non-hispanic white and other (ie native american, unk) race use 1983-87 rates
         avg non-hispanic white and other (ie native american, unk) race use 1992-96 rates

   All other races use the same race specific rates for abs risk projections for the
   women under investigation as well as for the race specific avg abs risk

   AgeMen  now recodes as:   0=[14,99]            1=(11,14)   2=(0,11]
   Age1st  now recodes as:   0=(AgeMen,20) U 99   1=[20,25)   2=[25,30) U 98   3=[30,98)


NCI BrCa Risk Assessment Macro (NCI BCRAM)  Version 2.0                          08/12/11

Incorporating absolute risk projections for Asian-Americans which comprise the following:

   Race= 6   Chinese-American
         7   Japanese-American
         8   Filipino-American
         9   Hawaiian
        10   Other Pacific Islanders
        11   Other Asian-American

   ref:  Projecting Individualized Absolute Invasive Breast Cancer Risk in Asian and
         Pacific Islander American Women
         Matsuno RK, Costantino JP, Ziegler RG, Anderson GL, Li H, Pee D, Gail MH
         JNCI (2011)


NCI BrCa Risk Assessment Macro (NCI BCRAM)  Version 1.1                          09/15/10

   Modify to perform abs risk projection for white women using SEER 1995-2003 incidence
   and competeing hazards.  1983-87 SEER rates and hazards are preserved as well:

   i.e.  Race=1  white abs risk based on SEER 1983:87 BrCa incidences and competing
                 hazards (rates used by the (B)reast (C)ancer (R)isk (A)ssessment (T)ool
                 ie BCRAT reported on in the following article  JNCI  91(18):1541-8  2010)

   ref: Validation studies for models projecting the risk of invasive and total breast
        cancer incidence
        Costantino JP, Gail MH, Pee D, Anderson S, Redmond CK, Benichou J, Wieand HS
        JNCI 91(18):1541-8  (1999)

      Race=5  white abs risk based on SEER 1995-03 BrCa incidences and competing hazards
             (rates reported on in the following article  JCO 28;2411:2417,  2010)

   ref: Effect of changing breast cancer incidence rates on the calibration of the Gail Model
        Schonfeld S, Pee D, Greenlee R, Hartge P, Lacey J, Park Y, Schatzkin A, Visvanathan K,
        Pfeiffer R
        JCO 28:2411=2417 (2010)


NCI BrCa Risk Assessment Macro (NCI BCRAM)  Version 1.0                          05/01/09

   SAS macro to project for absolute risk based on the Gail RR (whites, hispanic, others)
   or CARE RR (blacks) models.  1-AR, composite breast cancer incidences, competing hazards
   handling of missing covariate values and covariate editing procedures follow NCI BrCa
   Risk Assessment Tool (NCI BCRAT).



This program consists of two parts:

(1)  Readme section (the next 350+ lines of comments) describes:

        o required input variables,
        o valid values for input variables,
        o restrictions  on input variables,
        o error codes,
        o recoding rules for relative risk covariates,
        o structure of the sas macro,
        o listing of a sample input data set,
        o listing of the output data set obtained by applying the macro to the sample
          input data set.

(2)  The sas macro itself starting after the Readme section and which consists of 750+
     lines of sas code.




Readme section.


Input data:
----------
In_File= should "point" to a SAS data set containing all the required input data
items needed  to perform risk projections, such as initial age, projection age, BrCa
relative risk covariates and race.  See the paragraph "Input data items ... " below,
for a detailed description of all required data items.


Output data:
-----------
Out_File= should "point" to a SAS output data set which will contain the projected
absolute risk of BrCa as well as the original input data items.


Macro structure:
---------------
        Macro             Macro
        name              parameters                   "points" to

%macro  BrCa_RAM         (In_File     =,                name of input  sas data set
                          Out_File    =,                name of output sas data set

                          WID         =,                woman's ID #    1,2,3 .... postive integers

                          T1          =,                initial age,    age at beginning of
                                                                        projection interval

                          T2          =,                projection age, age at end of
                                                                        projection interval

                          N_Biop      =,                # biopsies performed
                          HyperPlasia =,                does biopsy exhibit atypical hyperplasia?

                          AgeMen      =,                age at menarchy
                          Age1st      =,                age at 1st live birth
                          N_Rels      =,                # 1st degree relatives with brca

                          Race        =,                race

                                                        all the above quantities are required
                                                        inputs to BrCa_RAM

                                                        following quantities are returned by
                                                        BrCa_RAM

                          CharRace    =,                2 character race abbreviation

                          RR_Star1    =,                women's relative risk of BrCa at ages lt 50
                          RR_Star2    =,                women's relative risk of BrCa at ages ge 50

                          AbsRsk      =,                absolute risk of BrCa in %
                          AbsRskAvg   =);               absolute risk of BrCa in % for an avg women

appropriate sas file/sas variable names must be associated with all macro parameters on the
invocation of the sas macro  "BrCa_RAM".

For example by coding  "In_File = AARPin"  tells the macro that the user created
sas file  "AARPin"  is to be used for input of variables.  Similarly, coding
"N_Biop = Num_Biops",  lets the macro know that the sas variable "Num_Biops" in the sas
input file  "AARPin"  contiains the count of the # of biopsies performed.

To involke the sas macro in your sas program, an %include statement must be coded in your
sas program, which points to  BrCa_RAM  and the folder where it is stored.  For example:

the statement: %include "BrCa_RAM";                points to the sas macro  BrCa_RAM
                                                   residing in your current directory

the statement: %include "c:\sas.macro\BrCa_RAM";   points to the sas macro  BrCa_RAM
                                                   stored in the directory c:\sas.macro





Input data items needed to project for BrCa absolute risk and consistency requirements:

Macro
parameter      Definition                    Valid values

WID            Woman's ID                    positive integer 1,2,3...

T1             Initial         age           all real numbers T1 in [20,90)
T2             BrCa projection age           all real numbers T2 such that  T1 < T2

               CONSTRAINT on T1 and T2:      20 <= T1 < T2 <= 90

N_Biop         # of biopsies                 0,1,2 ...       99=unk (99 recoded to 0)

HyperPlasia    Did biopsy display            0=no,  1=yes,   99=unk or not applicable for no biopsy
               atypical hyperplasia?

AgeMen         Age at menarchy               less than or equal to Initial age, 99=unk


Age1st         Age at first live birth       greater or equal to age at menarchy  and
                                             less than or equal to initial age.
                                             98=nulliparous,
                                             99=unk

N_Rels         # 1st degree relatives        0,1,2 ...       99=unk
               with BrCa

Race           Race                          1=Wh   white 1983-87 SEER rates  (rates used
                                                                               in NCI BCRAT)
                                             2=AA   african-american,
                                             3=Hi   hispanic,
                                             4=NA   other                     (native americans
                                                                               and unknown race)

                                             6=Ch   chinese                   (6-11 are asian-
                                             7=Ja   japanese                            pacific
                                             8=Fi   filipino                            islandrs)
                                             9=Hw   hawaiian
                                            10=oP   other pacific islander
                                            11=oA   other asian

                                             note that hispanic and other ethnic women
                                             risks are based on white women log relative
                                             risks.  hispanic women risk are based on
                                             hispanic seer rates while other women
                                             risk are based on white women seer rates

                                             avgerage other women rates are also based on
                                             average white women seer rates as well.


Recoding and checking of relative risk covariate values performed in this program:

                                     raw value                       recoded to

N_Biop: # biopsies                   0 or 99 (unk or not applicable)          0
                                     1                                        1
                                     2,3,4 ... and not 99                     2


AgeMen: age at menarchy              14,15,16 ... 99 (unk)                    0
                                     12,13                                    1
                                     11 and younger                           2


Age1st: age at 1st live birth        19 and younger  or  99 (unk)             0
                                     20,21,22,23,24                           1
                                     25,26,27,28,29  or  98(nulliparous)      2
                                     30,31,32 ...    and not 98 and not 99    3


N_Rels: # 1st degree rel with BrCa   0 or 99 (unk)                            0
                                     1                                        1
                                     2,3,4 ... and not 99                     2


Consistency patterns for  # of Biopsies and Hyperplasia:

Requirment: (A) N_Biops = 0  or   99  then  Hyperplasia  MUST = 99 (not applicable)
            (B) N_Biops > 0 and < 99  then  Hyperplasia       =  0, 1 or 99

if ANY of the above 2 REQUIREMENTS are violated, the absolute risk will be set to the
sas missing value ".".  The consequences to the relative risk (RR) for the above two
requirements is:

(A) # biopsies = 0 or   99  &  Hyperplasia  =99 (not applicable) inflates  RR  by  1.00

(B) # biopsies > 0 and <99  &  Hyperplasia  = 0 ( no hyprplasia) inflates  RR  by  0.93
                                            = 1 (yes hyprplasia) inflates  RR  by  1.82
                                            =99 (unk hyprplasia) inflates  RR  by  1.00


Edit checking for remaining relative risk covariates, AgeMen, Age1st and N_Rels:

AgeMen:  age at menarchy must be postive integer less than equal to initial age T1

   NOTE  For African-American women  AgeMen <= 11 are grouped with AgeMen = 12 or 13


Age1st:  age at 1st live birth must be postive integer greater than equal to AgeMen and
         less than or equal to Initial age T1

   NOTE  For African-American women Age1st is not included in the RR model and all values
         for this variable are recoded to 0


N_Rels:  # of 1st degree relatives with BrCa must be 0,1,2...

   NOTE  For Asian-Americans  Race=6-11  # 1st degree relative  coded value of 2 gets grouped with 1




Following is a listing of the sample raw input data set "Sample.in"
(column heading included for clarity):

                            Num    Hyp    Age    Age    Num
  IDD       T1       T2    Biop   Plas    Men    1st    Rel        Race

    1     45.2     53.3      99     99     10     20      1           0
    2     45.2     53.3      99      1     10     20      1           1
    3     45.2     53.3      99      0     10     20      1           2
    4     45.2     53.3       0     99     10     20      1           3
    5     45.2     53.3       1     99     10     20      1           4
    6     45.2     53.3       1     99     14     19      1           5
    7     45.2     53.3      99     99     99     19      1           6
    8     45.2     53.3       1      1     14     19      1           7
    9     45.2     53.3      99      1     14     99      1           8
   10     45.2     53.3       1      0     14     19      1           9
   11     45.2     53.3      99      0     99     99      1          10
   12     45.2     53.3       0      0     14     19      1          11
   13     45.2     53.3       0     99     10     20      1          12
   14     45.2     53.3       0      1     10     20      1           0
   15     45.2     53.3       0      0     10     20      1           1
   16     45.2     53.3       1      0     10     20      1           2
   17     35.0     40.0       4     99     11     25      0           3
   18     35.0     40.0       4     99     11     98      0           4
   19     35.0     40.0       4     99     11     10      0           5
   20     35.0     40.0       4     99     36     25      0           6
   21     27.0     90.0      99     99     13     22      0           7
   22     27.0     90.0      99     99     13     22     99           8
   23     18.0     26.0      99     99     13     22     99           9
   24     27.0     26.0      99     99     13     22     99          10
   25     85.0     91.0      99     99     13     22     99          11
   26     86.0     90.0      99     99     13     22     99          12


After the absolute risks have been generated, descriptive statistics by applying PROC
MEANS to the quantities Error_Ind, AbsRsk, RR_Star1 and RR_Star2 is performed.  When
the mean and standard deviation for the variable  "Error_Ind"  is 0, implies that no
errors have not been found.  Otherwise when the mean and std for  "Error_Ind" is not 0,
implies that errors have been found.  When errors are found, the # of records with
errors is the count asscociated with "AbsRsk" listed under NMiss (# of missing).
Furthermore, a listing file for erroronious records follows the PROC Means output.
For example:

BrCa_RAM,  sas macro to project for BrCa absolute risk                September 15, 2010
Quick check for errornous records on input file

IF MEAN OF  'Error_Ind'   EQUALS  0,   ERROR  FREE.    ERROR LISTING BELOW WILL BE EMPTY.
IF MEAN OF  'Error_Ind'   IS NOT  0,   ERRORS EXISTS.  CHECK ERROR LISTING BELOW.

(# of records with errors is the # listed under the NMiss column in the 'AbsRsk' line)

                                                                                        N
Variable         Label                                           Mean   Std Dev   N  Miss
-----------------------------------------------------------------------------------------
Error_Ind        If mean not 0, implies ERROR in file         0.57692   0.50383  26     0
Absolute_Risk    Abs risk(%) of BrCa in age interval [T1,T2)  3.76766   2.57844  11    15
RR_Star1         Relative risk age lt 50                      3.43948   1.92321  13    13
RR_Star2         Relative risk age ge 50                      2.86656   1.54840  13    13
-----------------------------------------------------------------------------------------


Since NMiss=15 for Absolute Risk, we note that the error listing lists 15 records below:


Error listing for the input file

  ID                 #  Hypr  Hypr  Age  Age    #             RR      RR              Pat
   #    T1    T2  Biop  plas    RR  Men  1st  Rel   Race  Age<50  Age>50   AbsRsk(%)    #

   1  45.2  53.3    99    99  1.00   10   20    1      0     .       .          .      29
      45.2  53.3     0    99  1.00    2    1    1     ??

   2  45.2  53.3    99     1   .     10   20    1      1     .       .          .       .
      45.2  53.3     A     A   A      2    1    1     Wh

   3  45.2  53.3    99     0   .     10   20    1      2     .       .          .       .
      45.2  53.3     A     A   A      1    0    1     AA

   9  45.2  53.3    99     1   .     14   99    1      8     .       .          .       .
      45.2  53.3     A     A   A      0    0    1     Fi

  11  45.2  53.3    99     0   .     99   99    1     10     .       .          .       .
      45.2  53.3     A     A   A      0    0    1     oP

  12  45.2  53.3     0     0   .     14   19    1     11     .       .          .       .
      45.2  53.3     A     A   A      0    0    1     oA

  13  45.2  53.3     0    99  1.00   10   20    1     12     .       .          .      29
      45.2  53.3     0    99  1.00    2    1    1     ??

  14  45.2  53.3     0     1   .     10   20    1      0     .       .          .       .
      45.2  53.3     A     A   A      2    1    1     ??

  15  45.2  53.3     0     0   .     10   20    1      1     .       .          .       .
      45.2  53.3     A     A   A      2    1    1     Wh

  19  35.0  40.0     4    99  1.00   11   10    0      5     .       .          .       .
      35.0  40.0     2    99  1.00    2    .    0     Wo

  20  35.0  40.0     4    99  1.00   36   25    0      6     .       .          .       .
      35.0  40.0     2    99  1.00    .    .    0     Ch

  23  18.0  26.0    99    99  1.00   13   22   99      9     .       .          .       .
        .   26.0     0    99  1.00    1    .    0     Hw

  24  27.0  26.0    99    99  1.00   13   22   99     10    1.42    1.42        .      16
        .     .      0    99  1.00    1    1    0     oP

  25  85.0  91.0    99    99  1.00   13   22   99     11    1.42    1.42        .      16
      85.0    .      0    99  1.00    1    1    0     oA

  26  86.0  90.0    99    99  1.00   13   22   99     12     .       .          .      16
      86.0  90.0     0    99  1.00    1    1    0     ??


For each of the records with error, the record is listed followed by a line which gives
some indication as to where the error occured.  For example, the record with ID=2 has
an "A" listed under the 3 variables associated with Biopy i.e. N_Biop, Hyperplasia
and Hypr_RR.  This means that ID=2 has violated consistency defined by Requirement
(A) above. Similarly for IDs 3,9,11,12,14 and 15 which display violations of
Requirements (A).  For IDs 19 and 20, violation of AgeMen and/or Age1st consistency
are seen.  Note the SAS missing value "." listed under AgeMen and/or Age1st.
For IDs 23, 24 and 25 violation of T1 and/or T2 consistency requirements are seen.
Again, note the "." listed under T1 and/or T2.  This small sample data set "Sample.in"
in no way exhausts all the possible ways in which the data can be in error, but it should
give a guide and indication on how to check and correct errors when they do occur.


Statistical issues  should be directed to:   Dr. Mitchell Gail    gailm@exchange.nih.gov
Technical   details should be directed to:   Mr. David Pee        peed@imsweb.com


End of Readme section.

****************************************************************************************/


options  nocenter  ls=120  ps=9999  notes;
options  FORMCHAR="|----|+|---+=|-/\<>*";


***     BrCa_RAM      start of macro which performs BrCa absolute risk projection

        Modification/change of any code from this point onward should be avoided,
        i.e. from  "%macro    BrCa_RAM"  to the line which reads  "%mend    BrCa_RAM".
        roughly 750 lines of code,  Any changes to these codes are done at the user's
        risk, since changes may inadvertenly cause the macro to be fundamentally
        altered resulting in incorrect projections and/or abnormal termination

                    macro           all macro parameters need to "point" to appropriate
                    parameters      sas file or sas variable names upon invocation;

%macro  BrCa_RAM   (In_File         =,
                    Out_File        =,

                    WID             =,

                    T1              =,
                    T2              =,

                    N_Biop          =,
                    HyperPlasia     =,

                    AgeMen          =,
                    Age1st          =,
                    N_Rels          =,

                    Race            =,
                    CharRace        =,

                    RR_Star1        =,
                    RR_Star2        =,

                    AbsRsk          =,
                    AbsRskAvg       =);


   ***   sas system dataset which contains rr covariates for women of interest
         i.e. women whom we wish to project absolute risk based on their relative
         risk covariate values, initial age, projection age and race;
   data  TmpFile;      *** temporary working sas file containing rr covariate data;
   set  &In_File;      *** original  input   sas file containing rr covariate data;

         *** set raw file indicator to default value of 1;
         Raw_Ind = 1;


         title3 'BrCa_RAM,  sas macro to project for BrCa absolute risk';

                 Error_Ind = 0;                  *** edit error indicator;
         label   Error_Ind = "If mean not 0, implies ERROR in file";


         *** codes to test for consistency of T1 (initial age) and T2 (projection age);
         set_T1_Missing = &T1;
         set_T2_Missing = &T2;

         if (&T1 lt 20 or &T1 ge 90) then do;
            set_T1_Missing = .;
            Error_Ind      = 1;
         end;

         if (&T2 gt 90) then do;
            set_T2_Missing = .;
            Error_Ind      = 1;
         end;

         if (&T1 ge &T2) then do;
            set_T1_Missing = .;
            set_T2_Missing = .;
            Error_Ind      = 1;
         end;




         if (Raw_Ind eq 1) then do;
         *** rr covariates are in raw/original format;

            *** codes to test for consistency of N_Biop (#biopsies) and Hyperplasia;
            NB_Cat = -1;                          ***set NB_Cat to default value -1;

            if      ((&N_Biop eq 0  or &N_Biop eq 99) and &HyperPlasia ne 99)
            then do;
               NB_Cat             = .a;                          *** see REQUIREMENT (A);
               Error_Ind          =  1;
            end;
            else if ((&N_Biop gt 0 and &N_Biop lt 99) and (&Hyperplasia ne  0 and
                                                           &Hyperplasia ne  1 and
                                                           &Hyperplasia ne 99))
            then do;
               NB_Cat             = .b;                          *** see REQUIREMENT (B);
               Error_Ind          =  1;
            end;

            *** editing and recoding for N_Biop;
            if (NB_Cat eq -1) then do;   *** NB_Cat=-1 implies no REQUIREMENT violations;
               if      (&N_Biop eq  0  or  &N_Biop eq 99)  then  NB_Cat=0;
               else if (&N_Biop eq  1                   )  then  NB_Cat=1;
               else if (&N_Biop ge  2 and  &N_Biop ne 99)  then  NB_Cat=2;
               else                                              NB_Cat=.;
            end;


            *** editing and recoding for AgeMen;
            if     ((&AgeMen ge 14 and &AgeMen le &T1) or &AgeMen eq 99) then AM_Cat=0;
            else if( &AgeMen ge 12 and &AgeMen lt  14)                   then AM_Cat=1;
            else if( &AgeMen gt  0 and &AgeMen lt  12)                   then AM_Cat=2;
            else                                                              AM_Cat=.;

            *** for african-americans AgeMen code 2 (age<=11) grouped with code 1 (age=12,13);
            if     ( &Race eq 2 and AM_Cat eq 2)                         then AM_Cat=1;


            *** editing and recoding for Age1st;
            if     ( &Age1st lt &AgeMen and &AgeMen ne 99)               then AF_Cat=.;
            else if( &Age1st gt &T1 and &Age1st lt 98)                   then AF_Cat=.;
            else if( &Age1st lt  20  or &Age1st eq 99)                   then AF_Cat=0;
            else if( &Age1st ge  20 and &Age1st lt 25)                   then AF_Cat=1;
            else if((&Age1st ge  25 and &Age1st lt 30) or &Age1st eq 98) then AF_Cat=2;
            else if( &Age1st ge  30                  )                   then AF_Cat=3;
            else                                                              AF_Cat=.;

            *** for africn=-amercns Age1st is not a RR covar and not in RR model,  set to 0;
            if     ( &Race eq 2)                                         then AF_Cat=0;


            *** editing and recoding for N_Rels;
            if     ( &N_Rels eq  0  or &N_Rels eq 99)                    then NR_Cat=0;
            else if( &N_Rels eq  1                  )                    then NR_Cat=1;
            else if( &N_Rels ge  2 and &N_Rels lt 99)                    then NR_Cat=2;
            else                                                              NR_Cat=.;

            *** for asian-americans NR_Cat=2 is pooled with NR_Cat=1;
            if     ( &Race ge 6 and &Race le 11 and NR_Cat eq 2)         then NR_Cat=1;
         end;
         else if (Raw_Ind eq 0) then do;
         *** RR covariates have already been re-coded to 0, 1, 2 or 3(when necessary).
             NOTE: edit/consistency checks for all relative four risk covariates
                   not performed when Raw_Ind=0.  use this option at your own risk;
            NB_Cat = &N_Biop;
            AM_Cat = &AgeMen;
            AF_Cat = &Age1st;
            NR_Cat = &N_Rels;
         end;


         *** setting RR multiplicative factor for atypical hyperplasia;
         if      (NB_Cat eq 0)            then  R_Hyp = 1.00;           *** # Biopsy=0;
         else if (NB_Cat gt 0) then do;                                 *** # Biopsy>0;
            if      (&HyperPlasia eq  0)  then  R_Hyp = 0.93;
            else if (&HyperPlasia eq  1)  then  R_Hyp = 1.82;
            else if (&HyperPlasia eq 99)  then  R_Hyp = 1.00;
         end;


         set_HyprP_Missing = &HyperPlasia;
         set_R_Hyp_Missing =        R_Hyp;

         if      (NB_Cat eq .a)          then do;
            set_HyprP_Missing =    .a;
            set_R_Hyp_Missing =    .a;
         end;
         else if (NB_Cat eq .b)          then do;
            set_HyprP_Missing =    .b;
            set_R_Hyp_Missing =    .b;
         end;

         RacCat = 0;

         if (&Race ne  1  and
             &Race ne  2  and
             &Race ne  3  and
             &Race ne  4  and

             &Race ne  6  and
             &Race ne  7  and
             &Race ne  8  and
             &Race ne  9  and
             &Race ne 10  and
             &Race ne 11) then  RacCat = .U;


         if (NB_Cat eq .   or
             AM_Cat eq .   or
             AF_Cat eq .   or
             NR_Cat eq .   or
             RacCat eq .U) then  Error_Ind = 1;


         *** african-american RR model from CARE study:
             (1) eliminates  Age1st from model
             (2) groups      AgeMen=2 with AgeMen=1;

         if (&Race eq 2) then do;
                                  AF_Cat = 0;      *** setting=0 eliminates Age1st and
                                                       its interaction from RR model;

            if (AM_Cat eq 2) then AM_Cat = 1;      *** group AgeMen RR level 2 with 1;
         end;


         *** for asian-americans NR_Cat=2 is pooled with NR_Cat=1;      *** pool # rel >=2;
         if (&Race ge 6 and &Race le 11 and NR_Cat eq 2) then NR_Cat=1; *** with # rel  =1;


         if     (&Race eq  1) then &CharRace = "Wh";    *** white SEER 1983:87 BrCa Rate;
         else if(&Race eq  2) then &CharRace = "AA";    *** african-american;
         else if(&Race eq  3) then &CharRace = "Hi";    *** hispanic;
         else if(&Race eq  4) then &CharRace = "NA";    *** other race  i.e. native american;

         else if(&Race eq  6) then &CharRace = "Ch";    *** chinese    asian-pacific islandr;
         else if(&Race eq  7) then &CharRace = "Ja";    *** japanese;
         else if(&Race eq  8) then &CharRace = "Fi";    *** filipino;
         else if(&Race eq  9) then &CharRace = "Hw";    *** hawaiian;
         else if(&Race eq 10) then &CharRace = "oP";    *** other pacific islander;
         else if(&Race eq 11) then &CharRace = "oA";    *** other asian;
         else                      &CharRace = "??";    *** non-applicable race code;

         Key = 1;
   run;




   ***   set up h1*, h2, beta & F(t) with known constants used in the nci brca risk disk;
   data  H1_Star;                                  *** h1star, BrCa composite incidences;

         *** SEER BrCa incidence rates (current) non-hispanic white women;
         array  White_H1 (II)  WH1_1-WH1_14
        (0.00001000, 0.00007600, 0.00026600, 0.00066100, 0.00126500, 0.00186600,
         0.00221100, 0.00272100, 0.00334800, 0.00392300, 0.00417800, 0.00443900,
         0.00442100, 0.00410900);                                 *** SEER white 1983:87;


         *** SEER BrCa incidence rates for "avg" non-hispanic white women and
                                           "avg" other (native american) women;
         array  White_H1Avg (II)  WH1_Avg1-WH1_Avg14
        (0.00001220, 0.00007410, 0.00022970, 0.00056490, 0.00116450, 0.00195250,
         0.00261540, 0.00302790, 0.00367570, 0.00420290, 0.00473080, 0.00494250,
         0.00479760, 0.00401060);                                 *** SEER white 1992:96;


         *** SEER BrCa indicdence rates (under study) for non-hispanic white women;
         array  White_nH1 (II)  WH1_n1-WH1_n14
        (0.0000120469, 0.0000746893, 0.0002437767, 0.0005878291, 0.0012069622, 0.0019762053,
         0.0026200977, 0.0033401788, 0.0039743676, 0.0044875763, 0.0048945499, 0.0051610641,
         0.0048268456, 0.0040407389);                           *** SEER white 1995:2003;


         array  Black_H1 (II)  BH1_1-BH1_14
        (0.00002696, 0.00011295, 0.00031094, 0.00067639, 0.00119444, 0.00187394,
         0.00241504, 0.00291112, 0.00310127, 0.00366560, 0.00393132, 0.00408951,
         0.00396793, 0.00363712);                                 *** SEER black 1994-98;

         array  Hspnc_H1 (II)  HH1_1-HH1_14
        (0.00002000, 0.00007100, 0.00019700, 0.00043800, 0.00081100, 0.00130700,
         0.00157400, 0.00185700, 0.00215100, 0.00251200, 0.00284600, 0.00275700,
         0.00252300, 0.00203900);                                 *** SEER hspan 1990:96;

         array  Other_H1 (II)  OH1_1-OH1_14
        (0.00001000, 0.00007600, 0.00026600, 0.00066100, 0.00126500, 0.00186600,
         0.00221100, 0.00272100, 0.00334800, 0.00392300, 0.00417800, 0.00443900,
         0.00442100, 0.00410900);                                 *** SEER white 1983:87;

         array  Chnes_H1 (II)  CH1_1-CH1_14
        (0.000004059636, 0.000045944465, 0.000188279352, 0.000492930493, 0.000913603501,
         0.001471537353, 0.001421275482, 0.001970946494, 0.001674745804, 0.001821581075,
         0.001834477198, 0.001919911972, 0.002233371071, 0.002247315779);
                                                             *** seer18 chinese  1998:02;

         array  Japns_H1 (II)  JP1_1-JP1_14
        (0.000000000001, 0.000099483924, 0.000287041681, 0.000545285759, 0.001152211095,
         0.001859245108, 0.002606291272, 0.003221751682, 0.004006961859, 0.003521715275,
         0.003593038294, 0.003589303081, 0.003538507159, 0.002051572909);
                                                             *** seer18 japanese 1998:02;

         array  Filip_H1 (II)  FP1_1-FP1_14
        (0.000007500161, 0.000081073945, 0.000227492565, 0.000549786433, 0.001129400541,
         0.001813873795, 0.002223665639, 0.002680309266, 0.002891219230, 0.002534421279,
         0.002457159409, 0.002286616920, 0.001814802825, 0.001750879130);
                                                             *** seer18 filipino 1998:02;

         array  Hawai_H1 (II)  HW1_1-HW1_14
        (0.000045080582, 0.000098570724, 0.000339970860, 0.000852591429, 0.001668562761,
         0.002552703284, 0.003321774046, 0.005373001776, 0.005237808549, 0.005581732512,
         0.005677419355, 0.006513409962, 0.003889457523, 0.002949061662);
                                                             *** seer18 hawaiian 1998:02;

         array  OtrPI_H1 (II)  OP1_1-OP1_14
        (0.000000000001, 0.000071525212, 0.000288799028, 0.000602250698, 0.000755579402,
         0.000766406354, 0.001893124938, 0.002365580107, 0.002843933070, 0.002920921732,
         0.002330395655, 0.002036291235, 0.001482683983, 0.001012248203);
                                                          *** seer18 otr pac isl 1998:02;

         array  OtrAs_H1 (II)  OA1_1-OA1_14
        (0.000012355409, 0.000059526456, 0.000184320831, 0.000454677273, 0.000791265338,
         0.001048462801, 0.001372467817, 0.001495473711, 0.001646746198, 0.001478363563,
         0.001216010125, 0.001067663700, 0.001376104012, 0.000661576644);
                                                            *** seer18 otr asian 1998:02;





         array  Ages     (II)  A1-A14
        (20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85);

         II  = .;
         Key = 1;
   run;


   data  H2;                                               *** h2,     Competing hazards;

         *** nchs competing mortality (current) for non-hispanic white women;
         array  White_H2 (II)  WH2_1-WH2_14
        (0.00049300, 0.00053100, 0.00062500, 0.00082500, 0.00130700, 0.00218100,
         0.00365500, 0.00585200, 0.00943900, 0.01502800, 0.02383900, 0.03883200,
         0.06682800, 0.14490800);                                 *** NCHS white 1985:87;


         *** nchs competing mortality for "avg" non-hispanic white women and
                                          "avg" other (native american) women;
         array  White_H2Avg (II)  WH2_Avg1-WH2_Avg14
        (0.00044120, 0.00052540, 0.00067460, 0.00090920, 0.00125340, 0.00195700,
         0.00329840, 0.00546220, 0.00910350, 0.01418540, 0.02259350, 0.03611460,
         0.06136260, 0.14206630);                                 *** NCHS white 1992:96;


         *** nchs competing mortality (under study) for non-hispanic white women;
         array  White_nH2 (II)  WH2_n1-WH2_n14
        (0.0004000377, 0.0004280396, 0.0005656742, 0.0008474486, 0.0012752947, 0.0018601059,
         0.0028780622, 0.0046903348, 0.0078835252, 0.0127434461, 0.0208586233, 0.0335901145,
         0.0575791439, 0.1377327125);                             *** NCHS white 1995:2003;


         array  Black_H2 (II)  BH2_1-BH2_14
        (0.00074354, 0.00101698, 0.00145937, 0.00215933, 0.00315077, 0.00448779,
         0.00632281, 0.00963037, 0.01471818, 0.02116304, 0.03266035, 0.04564087,
         0.06835185, 0.13271262);                                 *** NCHS black 1996-00;

         array  Hspnc_H2 (II)  HH2_1-HH2_14
        (0.00043700, 0.00053300, 0.00070000, 0.00089700, 0.00116300, 0.00170200,
         0.00264600, 0.00421600, 0.00696000, 0.01086700, 0.01685800, 0.02515600,
         0.04186600, 0.08947600);                                 *** NCHS hspan 1990:96;

         array  Other_H2 (II)  OH2_1-OH2_14
        (0.00049300, 0.00053100, 0.00062500, 0.00082500, 0.00130700, 0.00218100,
         0.00365500, 0.00585200, 0.00943900, 0.01502800, 0.02383900, 0.03883200,
         0.06682800, 0.14490800);                                 *** NCHS white 1985:87;

         array  Chnes_H2 (II)  CH2_1-CH2_14
        (0.000210649076, 0.000192644865, 0.000244435215, 0.000317895949, 0.000473261994,
         0.000800271380, 0.001217480226, 0.002099836508, 0.003436889186, 0.006097405623,
         0.010664526765, 0.020148678452, 0.037990796590, 0.098333900733);
                                                     *** NCHS mortality chinese  1998:02;

         array  Japns_H2 (II)  JP2_1-JP2_14
        (0.000173593803, 0.000295805882, 0.000228322534, 0.000363242389, 0.000590633044,
         0.001086079485, 0.001859999966, 0.003216600974, 0.004719402141, 0.008535331402,
         0.012433511681, 0.020230197885, 0.037725498348, 0.106149118663);
                                                     *** NCHS mortality japanese 1998:02;

         array  Filip_H2 (II)  FP2_1-FP2_14
        (0.000229120979, 0.000262988494, 0.000314844090, 0.000394471908, 0.000647622610,
         0.001170202327, 0.001809380379, 0.002614170568, 0.004483330681, 0.007393665092,
         0.012233059675, 0.021127058106, 0.037936954809, 0.085138518334);
                                                     *** NCHS mortality filipino 1998:02;

         array  Hawai_H2 (II)  HW2_1-HW2_14
        (0.000563507269, 0.000369640217, 0.001019912579, 0.001234013911, 0.002098344078,
         0.002982934175, 0.005402445702, 0.009591474245, 0.016315472607, 0.020152229069,
         0.027354838710, 0.050446998723, 0.072262026612, 0.145844504021);
                                                     *** NCHS mortality hawaiian 1998:02;

         array  OtrPI_H2 (II)  OP2_1-OP2_14
        (0.000465500812, 0.000600466920, 0.000851057138, 0.001478265376, 0.001931486788,
         0.003866623959, 0.004924932309, 0.008177071806, 0.008638202890, 0.018974658371,
         0.029257567105, 0.038408980974, 0.052869579345, 0.074745721133);
                                                  *** NCHS mortality otr pac isl 1998:02;

         array  OtrAs_H2 (II)  OA2_1-OA2_14
        (0.000212632332, 0.000242170741, 0.000301552711, 0.000369053354, 0.000543002943,
         0.000893862331, 0.001515172239, 0.002574669551, 0.004324370426, 0.007419621918,
         0.013251765130, 0.022291427490, 0.041746550635, 0.087485802065);
                                                    *** NCHS mortality otr asian 1998:02;

         II  = .;
         Key = 1;
   run;


   data  LN_RR;                                    *** beta=lnRR,   from Gail/CARE model;

         array  White_Beta (JJ)  W_NB_Beta      W_AM_Beta     W_AF_Beta     W_NR_Beta
                                 W_AC_NB_Beta   W_AF_NR_Beta
                                (0.5292641686,  0.0940103059, 0.2186262218, 0.9583027845,
                                -0.2880424830, -0.1908113865);             *** Gail lnRR;

         array  Black_Beta (JJ)  B_NB_Beta      B_AM_Beta     B_AF_Beta     B_NR_Beta
                                 B_AC_NB_Beta   B_AF_NR_Beta
                                (0.1822121131   0.2672530336  0.0           0.4757242578
                                -0.1119411682   0.0);                      *** CARE lnRR;

         array  Hspnc_Beta (JJ)  H_NB_Beta      H_AM_Beta     H_AF_Beta     H_NR_Beta
                                 H_AC_NB_Beta   H_AF_NR_Beta
                                (0.5292641686,  0.0940103059, 0.2186262218, 0.9583027845,
                                -0.2880424830, -0.1908113865);       *** Gail white lnRR;

         array  Other_Beta (JJ)  O_NB_Beta      O_AM_Beta     O_AF_Beta     O_NR_Beta
                                 O_AC_NB_Beta   O_AF_NR_Beta
                                (0.5292641686,  0.0940103059, 0.2186262218, 0.9583027845,
                                -0.2880424830, -0.1908113865);       *** Gail white lnRR;

         array  Asian_Beta (JJ)  A_NB_Beta      A_AM_Beta     A_AF_Beta     A_NR_Beta
                                 A_AC_NB_Beta   A_AF_NR_Beta
                                (0.55263612260619, 0.07499257592975, 0.27638268294593, 0.79185633720481,
                                 0.0,           0.0);                       *** APA lnRR;


         array  Beta_Name (JJ) $ CBeta1-CBeta6 ('N_Biop', 'AgeMen', 'AgeFst',  'N_Rels',
                                                'A50*NB', ' AF*NR');

         JJ  = .;
         Key = 1;
   run;


   data  FofT;                                            *** 1-Attributable Risk = F(t);

         array  White_1_AR (KK)  W_1_AR_1      W_1_AR_2  ( 0.5788413,        0.5788413);
         array  Black_1_AR (KK)  B_1_AR_1      B_1_AR_2  ( 0.72949880,       0.74397137);
         array  Hspnc_1_AR (KK)  H_1_AR_1      H_1_AR_2  ( 0.5788413,        0.5788413);
         array  Other_1_AR (KK)  O_1_AR_1      O_1_AR_2  ( 0.5788413,        0.5788413);
         array  Asian_1_AR (KK)  A_1_AR_1      A_1_AR_2  ( 0.47519806426735, 0.50316401683903);
         KK  = .;
         Key = 1;
   run;




   ***   The following 5 data steps, gathers all the needed parameters/constants
         and the input data set together to get ready for risk projection;
   data  TmpFile;
   merge TmpFile  H1_Star;
   by    Key;
   run;


   data  TmpFile;
   merge TmpFile  H2;
   by    Key;
   run;


   data  TmpFile;
   merge TmpFile  LN_RR;
   by    Key;
   run;


   data  TmpFile  (drop=Key);
   merge TmpFile  FofT;
   by    Key;
   run;


   data  TmpFile;
   set   TmpFile;

         array  White_H1    (II)     WH1_1-WH1_14;     *** h1star, BrCa composite incidences;
         array  White_nH1   (II)    WH1_n1-WH1_n14;
         array  White_H1Avg (II)  WH1_Avg1-WH1_Avg14;  *** BrCa rates for "avg" white women and
                                                                          "avg" other (native american) women;
         array  Black_H1    (II)     BH1_1-BH1_14;
         array  Hspnc_H1    (II)     HH1_1-HH1_14;
         array  Other_H1    (II)     OH1_1-OH1_14;
         array  Chnes_H1    (II)     CH1_1-CH1_14;
         array  Japns_H1    (II)     JP1_1-JP1_14;
         array  Filip_H1    (II)     FP1_1-FP1_14;
         array  Hawai_H1    (II)     HW1_1-HW1_14;
         array  OtrPI_H1    (II)     OP1_1-OP1_14;
         array  OtrAs_H1    (II)     OA1_1-OA1_14;


         array  White_H2    (II)     WH2_1-WH2_14;     *** h2,     Competing hazards;
         array  White_nH2   (II)    WH2_n1-WH2_n14;
         array  White_H2Avg (II)  WH2_Avg1-WH2_Avg14;  *** competing haz for "avg" white women and
                                                                             "avg" other (native american) women;
         array  Black_H2    (II)     BH2_1-BH2_14;
         array  Hspnc_H2    (II)     HH2_1-HH2_14;
         array  Other_H2    (II)     OH2_1-OH2_14;
         array  Chnes_H2    (II)     CH2_1-CH2_14;
         array  Japns_H2    (II)     JP2_1-JP2_14;
         array  Filip_H2    (II)     FP2_1-FP2_14;
         array  Hawai_H2    (II)     HW2_1-HW2_14;
         array  OtrPI_H2    (II)     OP2_1-OP2_14;
         array  OtrAs_H2    (II)     OA2_1-OA2_14;


         array  Ages      (II)    A1-A14;
         array  AgesP5    (II)    AP1-AP14;

         do II = 1 to 14;
           AgesP5 = Ages + 5;
         end;


         array  White_Beta (JJ)   W_NB_Beta     W_AM_Beta     W_AF_Beta  W_NR_Beta
                                  W_AC_NB_Beta  W_AF_NR_Beta;

         array  Black_Beta (JJ)   B_NB_Beta     B_AM_Beta     B_AF_Beta  B_NR_Beta
                                  B_AC_NB_Beta  B_AF_NR_Beta;

         array  Hspnc_Beta (JJ)   H_NB_Beta     H_AM_Beta     H_AF_Beta  H_NR_Beta
                                  H_AC_NB_Beta  H_AF_NR_Beta;

         array  Other_Beta (JJ)   O_NB_Beta     O_AM_Beta     O_AF_Beta  O_NR_Beta
                                  O_AC_NB_Beta  O_AF_NR_Beta;

         array  Asian_Beta (JJ)   A_NB_Beta     A_AM_Beta     A_AF_Beta  A_NR_Beta
                                  A_AC_NB_Beta  A_AF_NR_Beta;


         array  Beta_Name  (JJ) $ CBeta1-CBeta6;


         *** 1-Attributable Risk = F(t);
         array  White_1_AR (KK)  W_1_AR_1      W_1_AR_2;
         array  Black_1_AR (KK)  B_1_AR_1      B_1_AR_2;
         array  Hspnc_1_AR (KK)  H_1_AR_1      H_1_AR_2;
         array  Other_1_AR (KK)  O_1_AR_1      O_1_AR_2;
         array  Asian_1_AR (KK)  A_1_AR_1      A_1_AR_2;



         *** arrays to hold each 5yr age cat rate for each year in the 5yr age cat;
         array  WrkH1_1    (I5)  W1_01_1-W1_01_5;                            *** [20:25);
         array  WrkH1_2    (I5)  W1_02_1-W1_02_5;                            *** [25:30);
         array  WrkH1_3    (I5)  W1_03_1-W1_03_5;                            *** [30:35);
         array  WrkH1_4    (I5)  W1_04_1-W1_04_5;                            *** [35:40);
         array  WrkH1_5    (I5)  W1_05_1-W1_05_5;                            *** [40:45);
         array  WrkH1_6    (I5)  W1_06_1-W1_06_5;                            *** [45:50);
         array  WrkH1_7    (I5)  W1_07_1-W1_07_5;                            *** [50:55);
         array  WrkH1_8    (I5)  W1_08_1-W1_08_5;                            *** [55:60);
         array  WrkH1_9    (I5)  W1_09_1-W1_09_5;                            *** [60:65);
         array  WrkH1_10   (I5)  W1_10_1-W1_10_5;                            *** [65:70);
         array  WrkH1_11   (I5)  W1_11_1-W1_11_5;                            *** [70:75);
         array  WrkH1_12   (I5)  W1_12_1-W1_12_5;                            *** [75:80);
         array  WrkH1_13   (I5)  W1_13_1-W1_13_5;                            *** [80:85);
         array  WrkH1_14   (I5)  W1_14_1-W1_14_5;                            *** [85:90);

         array  Wrk_H1     (II) WrkH1_1-WrkH1_14;               *** h1   for this record;


         array  WrkH2_1    (I5)  W2_01_1-W2_01_5;                            *** [20:25);
         array  WrkH2_2    (I5)  W2_02_1-W2_02_5;                            *** [25:30);
         array  WrkH2_3    (I5)  W2_03_1-W2_03_5;                            *** [30:35);
         array  WrkH2_4    (I5)  W2_04_1-W2_04_5;                            *** [35:40);
         array  WrkH2_5    (I5)  W2_05_1-W2_05_5;                            *** [40:45);
         array  WrkH2_6    (I5)  W2_06_1-W2_06_5;                            *** [45:50);
         array  WrkH2_7    (I5)  W2_07_1-W2_07_5;                            *** [50:55);
         array  WrkH2_8    (I5)  W2_08_1-W2_08_5;                            *** [55:60);
         array  WrkH2_9    (I5)  W2_09_1-W2_09_5;                            *** [60:65);
         array  WrkH2_10   (I5)  W2_10_1-W2_10_5;                            *** [65:70);
         array  WrkH2_11   (I5)  W2_11_1-W2_11_5;                            *** [70:75);
         array  WrkH2_12   (I5)  W2_12_1-W2_12_5;                            *** [75:80);
         array  WrkH2_13   (I5)  W2_13_1-W2_13_5;                            *** [80:85);
         array  WrkH2_14   (I5)  W2_14_1-W2_14_5;                            *** [85:90);

         array  Wrk_H2     (II) WrkH2_1-WrkH2_14;               *** h2   for this record;



         *** arrays to hold each 5yr age cat "avg" white women and
                                             "avg" other (native american) women rate
             for each year in the 5yr age cat;
         array  AvgH1_1    (I5)  AW1_01_1-AW1_01_5;                          *** [20:25);
         array  AvgH1_2    (I5)  AW1_02_1-AW1_02_5;                          *** [25:30);
         array  AvgH1_3    (I5)  AW1_03_1-AW1_03_5;                          *** [30:35);
         array  AvgH1_4    (I5)  AW1_04_1-AW1_04_5;                          *** [35:40);
         array  AvgH1_5    (I5)  AW1_05_1-AW1_05_5;                          *** [40:45);
         array  AvgH1_6    (I5)  AW1_06_1-AW1_06_5;                          *** [45:50);
         array  AvgH1_7    (I5)  AW1_07_1-AW1_07_5;                          *** [50:55);
         array  AvgH1_8    (I5)  AW1_08_1-AW1_08_5;                          *** [55:60);
         array  AvgH1_9    (I5)  AW1_09_1-AW1_09_5;                          *** [60:65);
         array  AvgH1_10   (I5)  AW1_10_1-AW1_10_5;                          *** [65:70);
         array  AvgH1_11   (I5)  AW1_11_1-AW1_11_5;                          *** [70:75);
         array  AvgH1_12   (I5)  AW1_12_1-AW1_12_5;                          *** [75:80);
         array  AvgH1_13   (I5)  AW1_13_1-AW1_13_5;                          *** [80:85);
         array  AvgH1_14   (I5)  AW1_14_1-AW1_14_5;                          *** [85:90);

         array  Avg_H1     (II)  AvgH1_1-AvgH1_14;              *** h1   for this record;


         array  AvgH2_1    (I5)  AW2_01_1-AW2_01_5;                          *** [20:25);
         array  AvgH2_2    (I5)  AW2_02_1-AW2_02_5;                          *** [25:30);
         array  AvgH2_3    (I5)  AW2_03_1-AW2_03_5;                          *** [30:35);
         array  AvgH2_4    (I5)  AW2_04_1-AW2_04_5;                          *** [35:40);
         array  AvgH2_5    (I5)  AW2_05_1-AW2_05_5;                          *** [40:45);
         array  AvgH2_6    (I5)  AW2_06_1-AW2_06_5;                          *** [45:50);
         array  AvgH2_7    (I5)  AW2_07_1-AW2_07_5;                          *** [50:55);
         array  AvgH2_8    (I5)  AW2_08_1-AW2_08_5;                          *** [55:60);
         array  AvgH2_9    (I5)  AW2_09_1-AW2_09_5;                          *** [60:65);
         array  AvgH2_10   (I5)  AW2_10_1-AW2_10_5;                          *** [65:70);
         array  AvgH2_11   (I5)  AW2_11_1-AW2_11_5;                          *** [70:75);
         array  AvgH2_12   (I5)  AW2_12_1-AW2_12_5;                          *** [75:80);
         array  AvgH2_13   (I5)  AW2_13_1-AW2_13_5;                          *** [80:85);
         array  AvgH2_14   (I5)  AW2_14_1-AW2_14_5;                          *** [85:90);

         array  Avg_H2     (II)  AvgH2_1-AvgH2_14;              *** h2   for this record;


         array  Wrk_Beta   (JJ)  Beta1-Beta6;                   *** beta for this record;
         array  Wrk_1_AR   (KK)  One_AR1 One_AR2;               *** 1-AR for this record;


         *** initialize "avg white women"  and "avg" other (native american) women
             rate vectors now, and use these "avg" rates for "avg" white women  and
            "avg" other (native american) women projections when the value of
            "iloop=2"  later on in the macro;
         do II = 1 to 14;
            tmp1 = White_H1AVG;            *** 92-96 brca incidence for the 5yr age cat;
            tmp2 = White_H2AVG;            *** 92-96 competing hazs for the 5yr age cat;

            do I5 = 1 to 5;    *** fill in each yr of the 5yr cat with correct avg rate;
               Avg_H1 = tmp1;
               Avg_H2 = tmp2;
            end;
         end;


         ***  initialize rate vectors with the correct rates for each women under study
              based on her race;
         if      (&Race eq 1 or &Race eq 5) then do;                *** 1=white old rate;
            do II = 1 to 14;                                        *** 5=white new rate;
               if      (&Race eq 1) then do;
                  tmp1 = White_H1;          *** 83-87 brca incidence for the 5yr age cat;
                  tmp2 = White_H2;          *** 85-87 competing hazs for the 5yr age cat;
               end;
               else if (&Race eq 5) then do;
                  tmp1 = White_nH1;         *** 95-03 brca incidence for the 5yr age cat;
                  tmp2 = White_nH2;         *** 95-03 competing hazs for the 5yr age cat;
               end;

               do I5 = 1 to 5;  *** fill in each yr of the 5yr cat with the correct rate;
                  Wrk_H1 = tmp1;
                  Wrk_H2 = tmp2;
               end;
            end;

            do JJ = 1 to 6;                                                    *** ln RR;
               Wrk_Beta = White_Beta;
            end;

            do KK = 1 to 2;                                                    *** 1- AR;
               Wrk_1_AR = White_1_AR;
            end;
         end;
         else if (&Race eq 2) then do;                                         *** black;
            do II = 1 to 14;
               tmp1 = Black_H1;                   *** brca incidence for the 5yr age cat;
               tmp2 = Black_H2;                   *** competing hazs for the 5yr age cat;

               do I5 = 1 to 5;  *** fill in each yr of the 5yr cat with the correct rate;
                  Wrk_H1 = tmp1;
                  Wrk_H2 = tmp2;
               end;

            end;

            do JJ = 1 to 6;                                                    *** ln RR;
               Wrk_Beta = Black_Beta;
            end;

            do KK = 1 to 2;                                                    *** 1- AR;
               Wrk_1_AR = Black_1_AR;
            end;
         end;
         else if (&Race eq 3) then do;                                      *** hispanic;
            do II = 1 to 14;
               tmp1 = Hspnc_H1;                   *** brca incidence for the 5yr age cat;
               tmp2 = Hspnc_H2;                   *** competing hazs for the 5yr age cat;

               do I5 = 1 to 5;  *** fill in each yr of the 5yr cat with the correct rate;
                  Wrk_H1 = tmp1;
                  Wrk_H2 = tmp2;
               end;
            end;

            do JJ = 1 to 6;                                                    *** ln RR;
               Wrk_Beta = Hspnc_Beta;
            end;

            do KK = 1 to 2;                                                    *** 1- AR;
               Wrk_1_AR = Hspnc_1_AR;
            end;
         end;
         else if (&Race eq 4) then do;                                         *** Other;
            do II = 1 to 14;
               tmp1 = White_H1;       *** 83-87 white brca incidence for the 5yr age cat;
               tmp2 = White_H2;       *** 85-87 white competing hazs for the 5yr age cat;

               do I5 = 1 to 5;  *** fill in each yr of the 5yr cat with the correct rate;
                  Wrk_H1 = tmp1;
                  Wrk_H2 = tmp2;
               end;
            end;

            do JJ = 1 to 6;                                                    *** ln RR;
               Wrk_Beta = White_Beta;
            end;

            do KK = 1 to 2;                                                    *** 1- AR;
               Wrk_1_AR = White_1_AR;
            end;
         end;
         else if (&Race ge 6 and &Race le 11) then do;               *** Asian Americans;
            if      (&Race eq  6) then do;                                   *** Chinese;
               do II = 1 to 14;
                  tmp1 = Chnes_H1;        *** chinese brca incidence for the 5yr age cat;
                  tmp2 = Chnes_H2;        *** chinese competing hazs for the 5yr age cat;

                  do I5 = 1 to 5;   *** fill in each yr of the 5yr cat with correct rate;
                     Wrk_H1 = tmp1;
                     Wrk_H2 = tmp2;
                  end;
               end;
            end;
            if      (&Race eq  7) then do;                                  *** Japanese;
               do II = 1 to 14;
                  tmp1 = Japns_H1;       *** japanese brca incidence for the 5yr age cat;
                  tmp2 = Japns_H2;       *** japanese competing hazs for the 5yr age cat;

                  do I5 = 1 to 5;   *** fill in each yr of the 5yr cat with correct rate;
                     Wrk_H1 = tmp1;
                     Wrk_H2 = tmp2;
                  end;
               end;
            end;
            if      (&Race eq  8) then do;                                  *** Filipino;
               do II = 1 to 14;
                  tmp1 = Filip_H1;       *** filipino brca incidence for the 5yr age cat;
                  tmp2 = Filip_H2;       *** filipino competing hazs for the 5yr age cat;

                  do I5 = 1 to 5;   *** fill in each yr of the 5yr cat with correct rate;
                     Wrk_H1 = tmp1;
                     Wrk_H2 = tmp2;
                  end;
               end;
            end;
            if      (&Race eq  9) then do;                                  *** Hawaiian;
               do II = 1 to 14;
                  tmp1 = Hawai_H1;       *** hawaiian brca incidence for the 5yr age cat;
                  tmp2 = Hawai_H2;       *** hawaiian competing hazs for the 5yr age cat;

                  do I5 = 1 to 5;   *** fill in each yr of the 5yr cat with correct rate;
                     Wrk_H1 = tmp1;
                     Wrk_H2 = tmp2;
                  end;
               end;
            end;
            if      (&Race eq 10) then do;                           *** Otr Pacific Isl;
               do II = 1 to 14;
                  tmp1 = OtrPI_H1;    *** otr pac isl brca incidence for the 5yr age cat;
                  tmp2 = OtrPI_H2;    *** otr pac isl competing hazs for the 5yr age cat;

                  do I5 = 1 to 5;   *** fill in each yr of the 5yr cat with correct rate;
                     Wrk_H1 = tmp1;
                     Wrk_H2 = tmp2;
                  end;
               end;
            end;
            if      (&Race eq 11) then do;                                 *** Otr Asian;
               do II = 1 to 14;
                  tmp1 = OtrAs_H1;      *** otr asian brca incidence for the 5yr age cat;
                  tmp2 = OtrAs_H2;      *** otr asian competing hazs for the 5yr age cat;

                  do I5 = 1 to 5;   *** fill in each yr of the 5yr cat with correct rate;
                     Wrk_H1 = tmp1;
                     Wrk_H2 = tmp2;
                  end;
               end;
            end;

            do JJ = 1 to 6;                                                    *** ln RR;
               Wrk_Beta = Asian_Beta;
            end;

            do KK = 1 to 2;                                                    *** 1- AR;
               Wrk_1_AR = Asian_1_AR;
            end;
         end;
   run;




   *** document all constants;
   data  Dummy;
   set   TmpFile;

         file print;


         array  White_Beta (JJ)  W_NB_Beta     W_AM_Beta     W_AF_Beta  W_NR_Beta
                                 W_AC_NB_Beta  W_AF_NR_Beta;

         array  Black_Beta (JJ)  B_NB_Beta     B_AM_Beta     B_AF_Beta  B_NR_Beta
                                 B_AC_NB_Beta  B_AF_NR_Beta;

         array  Hspnc_Beta (JJ)  H_NB_Beta     H_AM_Beta     H_AF_Beta  H_NR_Beta
                                 H_AC_NB_Beta  H_AF_NR_Beta;

         array  Other_Beta (JJ)  O_NB_Beta     O_AM_Beta     O_AF_Beta  O_NR_Beta
                                 O_AC_NB_Beta  O_AF_NR_Beta;

         array  Asian_Beta (JJ)  A_NB_Beta     A_AM_Beta     A_AF_Beta  A_NR_Beta
                                 A_AC_NB_Beta  A_AF_NR_Beta;

         array  Beta_Name (JJ) $ CBeta1-CBeta6;

         if (_N_ eq 1) then do;
            put " ";
            put "Ln Relative Risk:                                          Beta";
            put " ";
            put "        Gail lnRR  CARE lnRR  Gail lnRR   Gail lnRR  AABCS lnRR";
            put "  Beta      White  AfrnAmrcn   Hispanic  NativAmrcn  AsianAmrcn";
            put " ";

            do JJ = 1 to 6;
               if     (JJ ne 3 and JJ ne 5 and JJ ne 6) then
                  put  Beta_Name  $char6.
                       White_Beta   11.6
                       Black_Beta   11.6
                       Hspnc_Beta   11.6
                       Other_Beta   12.6
                       Asian_Beta   12.6;

               else if (JJ eq 3) then
                  put  Beta_Name  $char6.
                       White_Beta   11.6
                                 "   0       "
                       Hspnc_Beta   11.6
                       Other_Beta   12.6
                       Asian_Beta   12.6;

               else if (JJ eq 5) then
                  put  Beta_Name  $char6.
                       White_Beta   11.6
                       Black_Beta   11.6
                       Hspnc_Beta   11.6
                       Other_Beta   12.6
                                "    0       ";

               else if (JJ eq 6) then
                  put  Beta_Name  $char6.
                       White_Beta   11.6
                                 "   0       "
                       Hspnc_Beta   11.6
                       Other_Beta   12.6
                                "    0       ";

            end;
         end;


         array  White_1_AR (KK)  W_1_AR_1      W_1_AR_2;
         array  Black_1_AR (KK)  B_1_AR_1      B_1_AR_2;
         array  Hspnc_1_AR (KK)  H_1_AR_1      H_1_AR_2;
         array  Other_1_AR (KK)  O_1_AR_1      O_1_AR_2;
         array  Asian_1_AR (KK)  A_1_AR_1      A_1_AR_2;

         if (_N_ eq 1) then do;
            put " ";
            put " ";
            put "1-Attributable Risk:                                         F(t)";
            put " ";
            put "AgeGrp       White  AfrnAmrcn   Hispanic  NativAmrcn  AsianAmrcn";

            put " ";

            do KK = 1 to 2;
               if      (KK eq 1) then
                  put  "Age< 50"
                       White_1_AR   11.6
                       Black_1_AR   11.6
                       Hspnc_1_AR   11.6
                       Other_1_AR   12.6
                       Asian_1_AR   12.6;
               else if (KK eq 2) then
                  put  "Age>=50"
                       White_1_AR   11.6
                       Black_1_AR   11.6
                       Hspnc_1_AR   11.6
                       Other_1_AR   12.6
                       Asian_1_AR   12.6;
            end;
         end;



         array  White_H1  (II)  WH1_1-WH1_14;
         array  White_nH1 (II)  WH1_n1-WH1_n14;
         array  Black_H1  (II)  BH1_1-BH1_14;
         array  Hspnc_H1  (II)  HH1_1-HH1_14;
         array  Other_H1  (II)  OH1_1-OH1_14;

         array  Ages      (II)  A1-A14;
         array  AgesP5    (II)  AP1-AP14;

         do II = 1 to 14;
           AgesP5 = Ages + 5;
         end;

         if (_N_ eq 1) then do;
            put " ";
            put " ";
            put "Breast cancer composite incidences:                                  h1*";
            put " ";
            put "    5yr  SEER 1983:87  SEER 1995:03     1994:98     1990:96     1983:87";
            put " AgeGrp         White         White  Afrn-Amrcn    Hispanic  NativAmrcn";
            put " ";

            do II = 1 to 14;
               put "[" Ages 2.0 ":"  AgesP5 2.0 ")"
                   White_H1  14.7
                   White_nH1 14.7
                   Black_H1  12.7
                   Hspnc_H1  12.7
                   Other_H1  12.7;
            end;
         end;


         array  White_H2  (II)  WH2_1-WH2_14;
         array  White_nH2 (II)  WH2_n1-WH2_n14;
         array  Black_H2  (II)  BH2_1-BH2_14;
         array  Hspnc_H2  (II)  HH2_1-HH2_14;
         array  Other_H2  (II)  OH2_1-OH2_14;

         if (_N_ eq 1) then do;
            put " ";
            put "Competing mortality excluding death from BrCa:                       h2";
            put " ";
            put "    5yr  SEER 1985:87  SEER 1995:03     1996-00     1990:96     1985:87";
            put " AgeGrp         White         White  Afrn-Amrcn    Hispanic  NativAmrcn";
            put " ";

            do II = 1 to 14;
               put "[" Ages 2.0 ":"  AgesP5 2.0 ")"
                   White_H2  14.7
                   White_nH2 14.7
                   Black_H2  12.7
                   Hspnc_H2  12.7
                   Other_H2  12.7;
            end;
         end;

   title4  "Listing of All constants required for BrCa absolute risk projections";
   run;


   data  Dummy;
   set   TmpFile;

         file print;


         array  Chnes_H1  (II)  CH1_1-CH1_14;
         array  Japns_H1  (II)  JP1_1-JP1_14;
         array  Filip_H1  (II)  FP1_1-FP1_14;
         array  Hawai_H1  (II)  HW1_1-HW1_14;
         array  OtrPI_H1  (II)  OP1_1-OP1_14;
         array  OtrAs_H1  (II)  OA1_1-OA1_14;

         array  Ages      (II)  A1-A14;
         array  AgesP5    (II)  AP1-AP14;

         do II = 1 to 14;
           AgesP5 = Ages + 5;
         end;


         if (_N_ eq 1) then do;
            put " ";
            put "Breast cancer composite incidences:                                              h1*";
            put " ";
            put "              SEER 18       SEER 18     SEER 18     SEER 18     SEER 18     SEER 18";
            put "    5yr     1998:2002     1998:2002   1998:2002   1998:2002   1998:2002   1998:2002";
            put " AgeGrp       Chinese      Japanese    Filipino    Hawaiian   OtrPacIsl    OtrAsian";
            put " ";

            do II = 1 to 14;
               put "[" Ages 2.0 ":"  AgesP5 2.0 ")"
                   Chnes_H1  14.7
                   Japns_H1  14.7
                   Filip_H1  12.7
                   Hawai_H1  12.7
                   OtrPI_H1  12.7
                   OtrAs_H1  12.7;
            end;
         end;


         array  Chnes_H2  (II)  CH2_1-CH2_14;
         array  Japns_H2  (II)  JP2_1-JP2_14;
         array  Filip_H2  (II)  FP2_1-FP2_14;
         array  Hawai_H2  (II)  HW2_1-HW2_14;
         array  OtrPI_H2  (II)  OP2_1-OP2_14;
         array  OtrAs_H2  (II)  OA2_1-OA2_14;

         if (_N_ eq 1) then do;
            put " ";
            put "Competing mortality excluding death from BrCa:                                   h2";
            put " ";
            put "              SEER 18       SEER 18     SEER 18     SEER 18     SEER 18     SEER 18";
            put "    5yr     1998:2002     1998:2002   1998:2002   1998:2002   1998:2002   1998:2002";
            put " AgeGrp       Chinese      Japanese    Filipino    Hawaiian   OtrPacIsl    OtrAsian";
            put " ";

            do II = 1 to 14;
               put "[" Ages 2.0 ":"  AgesP5 2.0 ")"
                   Chnes_H2  14.7
                   Japns_H2  14.7
                   Filip_H2  12.7
                   Hawai_H2  12.7
                   OtrPI_H2  12.7
                   OtrAs_H2  12.7;
            end;
         end;

   title4  "Listing of All constants required for BrCa absolute risk projections";
   run;




   *** BrCa risk projection;
   data  TmpFile;
   set   TmpFile;

      /* following two matrices  A_h1 (aka Avg_H1)  and  A_h2 (aka Avg_H2)
         used for "avg" white women  and "avg" other (native american) women rates

         The components of  A_h1 and  A_h2   AW1_01_1 -- AW1_14_5 (dim=70)
                                             AW2_01_1 -- AW2_14_5 (dim=70)

         have been initialized to  White_H1AVG  and  White_H2AVG
         respectively in a prior data step (code lines 1044-1056)

         average women for other races uses the same rates as the women
         under BrCa absolute risk projection.

         Dec 5, 2012  Pee
     */

         array  h1  (j_intvl) W1_01_1-W1_01_5    W1_02_1-W1_02_5    W1_03_1-W1_03_5
                              W1_04_1-W1_04_5    W1_05_1-W1_05_5    W1_06_1-W1_06_5
                              W1_07_1-W1_07_5    W1_08_1-W1_08_5    W1_09_1-W1_09_5
                              W1_10_1-W1_10_5    W1_11_1-W1_11_5    W1_12_1-W1_12_5
                              W1_13_1-W1_13_5    W1_14_1-W1_14_5;

         array  h2  (j_intvl) W2_01_1-W2_01_5    W2_02_1-W2_02_5    W2_03_1-W2_03_5
                              W2_04_1-W2_04_5    W2_05_1-W2_05_5    W2_06_1-W2_06_5
                              W2_07_1-W2_07_5    W2_08_1-W2_08_5    W2_09_1-W2_09_5
                              W2_10_1-W2_10_5    W2_11_1-W2_11_5    W2_12_1-W2_12_5
                              W2_13_1-W2_13_5    W2_14_1-W2_14_5;


         array A_h1 (j_intvl) AW1_01_1-AW1_01_5  AW1_02_1-AW1_02_5  AW1_03_1-AW1_03_5
                              AW1_04_1-AW1_04_5  AW1_05_1-AW1_05_5  AW1_06_1-AW1_06_5
                              AW1_07_1-AW1_07_5  AW1_08_1-AW1_08_5  AW1_09_1-AW1_09_5
                              AW1_10_1-AW1_10_5  AW1_11_1-AW1_11_5  AW1_12_1-AW1_12_5
                              AW1_13_1-AW1_13_5  AW1_14_1-AW1_14_5;

         array A_h2 (j_intvl) AW2_01_1-AW2_01_5  AW2_02_1-AW2_02_5  AW2_03_1-AW2_03_5
                              AW2_04_1-AW2_04_5  AW2_05_1-AW2_05_5  AW2_06_1-AW2_06_5
                              AW2_07_1-AW2_07_5  AW2_08_1-AW2_08_5  AW2_09_1-AW2_09_5
                              AW2_10_1-AW2_10_5  AW2_11_1-AW2_11_5  AW2_12_1-AW2_12_5
                              AW2_13_1-AW2_13_5  AW2_14_1-AW2_14_5;

         array  One_AR_RR (j_intvl)  One_AR_RR_01-One_AR_RR_70;

         array PI_j(j_intvl) Pi1-Pi70;

   /*
         <----- slow ----- fast ------> (changes)
         N_Biop, AgeMen, Age1st, N_Rels
         NB_Cat, AM_Cat, AF_Cat, NR_Cat

              3*      3*      4*      3= 108 patterns

          NB_Cat  3 levels      3*3*4*3 = 108 patterns
          AM_Cat  3 levels        3*4*3 =  36 patterns
          AF_Cat  4 levels          4*3 =  12 patterns
          NR_Cat  3 levels            3 =   3 patterns

         PattrnNumber = NB_Cat * 36  +
                        AM_Cat * 12  +
                        AF_Cat *  3  +
                        NR_Cat *  1  +  1;
   */

         PattrnNumber = NB_Cat * 36  +
                        AM_Cat * 12  +
                        AF_Cat *  3  +
                        NR_Cat *  1  +  1;



         LP1  = NB_Cat       * Beta1 +
                AM_Cat       * Beta2 +
                AF_Cat       * Beta3 +
                NR_Cat       * Beta4 +
                AF_Cat*NR_Cat* Beta6 +
                log(R_Hyp);              *** Linr Prdctr woman of interest at ages lt 50;

         LP2  = LP1                  +
                NB_Cat       * Beta5;    *** Linr Prdctr woman of interest at ages ge 50;


        &RR_Star1   = exp(LP1);               *** RRstar woman of interest at ages lt 50;
        &RR_Star2   = exp(LP2);               *** RRstar woman of interest at ages ge 50;


         iloop = 1;

         *** for a research tool, all we want is to find the absolute risk for each woman based
             on her current age, projection age and relative risk covariate values.  we are not
             interested in risk for the average women or lifetime risk for this women

             Dec 5, 2012   enhance macro with "avg" women BrCa absrsk projections;

         do while (iloop <= 2);               *** iloop = 1, do abs   risk  =2, do avg abs risk
                                                        = 3, LifeTime risk  =4, avg LT abs risk;

            if      (iloop = 1) then do;
               One_AR_RR1 = One_AR1*&RR_Star1;       ***(1-AR)*rr=(1-AR)*exp(xstar*) age lt 50;
               One_AR_RR2 = One_AR2*&RR_Star2;       ***(1-AR)*rr=(1-AR)*exp(xstar*) age ge 50;
            end;
            else if (iloop = 2) then do;
               One_AR_RR1 =                 1;       ***(1-AR)*rr=1         rr set to 1;
               One_AR_RR2 =                 1;       ***(1-AR)*rr=1       1-AR set to 1;
            end;
            else if (iloop = 3) then do;
               &T2        = 90;
               One_AR_RR1 = One_AR1*&RR_Star1;       ***(1-AR)*rr=(1-AR)*exp(xstar*) age lt 50;
               One_AR_RR2 = One_AR2*&RR_Star2;       ***(1-AR)*rr=(1-AR)*exp(xstar*) age ge 50;
            end;
            else if (iloop = 4) then do;
               &T2        = 90;
               One_AR_RR1 =                 1;       ***(1-AR)*rr=1         rr set to 1;
               One_AR_RR2 =                 1;       ***(1-AR)*rr=1       1-AR set to 1;
            end;

            do j_intvl = 1 to 70;
               if      (j_intvl le 30) then One_AR_RR = One_AR_RR1;
               else if (j_intvl gt 30) then One_AR_RR = One_AR_RR2;
            end;

            *** replace non-hispanic white women rates and other (native american) women rates
                with "avg" non-hispanic white women;
            if      (iloop = 2 and (&Race eq 1 or &Race eq 5 or &Race eq 4)) then do;
               *** 1=white old rate
                   4=native american (race=other)
                   5=white new rate

                   initializing vectors  h1  and  h2  respectively with
                                White_H1AVG  and  White_H2AVG;

               do j_intvl = 1 to 70;
                  h1 = A_h1;                   *** 92-96 brca incidence for the 5yr age cat;
                  h2 = A_h2;                   *** 92-96 competing hazs for the 5yr age cat;
               end;
            end;


            *** double iterated integral ala  eq 2.3  Benichou & Gail Biometrics 46,813-826;

            Strt_Intvl = floor(&T1) - 20 + 1;     *** example:  T1=21 T2=23, Strt_Intvl=21-20+1= 2;
            Endd_Intvl =  ceil(&T2) - 20 + 0;     ***                        EndD_Intvl=23-20+0= 3;
            NumbrIntvl =  ceil(&T2) - floor(&T1); ***                        NumbrIntvl=23-21  = 2;

            if      (Error_Ind eq 1) then
               RskWrk = .;                                      *** erroronous input record
                                                                    set abs risk to missing;

            else if (Error_Ind eq 0) then do;                   *** error free input record;
               RskWrk = 0;                                      *** calculate abs risk;
               Cum_H  = 0;

               do jj = 1 to NumbrIntvl;
                  j_intvl = Strt_Intvl + (jj - 1);

                  if      (NumbrIntvl gt 1 and jj gt          1
                                           and jj lt NumbrIntvl) then IntgrlLngth = 1;
                  else if (NumbrIntvl gt 1 and jj eq          1) then IntgrlLngth = 1 - (&T1 - floor(&T1));
                  else if (NumbrIntvl gt 1 and jj eq NumbrIntvl) then IntgrlLngth =     (&T2 - floor(&T2))*(&T2 gt floor(&T2)) +
                                                                                                           (&T2 eq floor(&T2));
                  else if (NumbrIntvl eq 1                     ) then IntgrlLngth =      &T2 - &T1;

                  Hj = h1*ONE_AR_RR + h2;

                  PI_j   = ((One_AR_RR*h1/Hj)*exp(-Cum_H)) * (1-exp(-Hj*IntgrlLngth));
                  RskWrk =  RskWrk + PI_j;
                  Cum_H  = Cum_H  + Hj*IntgrlLngth;
               end;
            end;

***         Key    = 1;

            RskWrk = 100* RskWrk;

            if      (iloop eq 1) then do;
               &AbsRsk    = RskWrk;
            end;
            else if (iloop eq 2) then do;
               &AbsRskAvg = RskWrk;
            end;

            iloop = iloop + 1;
         end;

         Key    = 1;

         output;


         label Beta1         =  "ln RR of # of biopsies"
               Beta2         =  "ln RR of age at menarchy"
               Beta3         =  "ln RR of age at 1st live birth"
               Beta4         =  "ln RR of # of 1st degree relatives with BrCa"
               Beta5         =  "ln RR of age ge 50 and # of biopsies"
               Beta6         =  "ln RR of age 1st birth and # relatives BrCa"

               One_AR1       =  "1-Attributable risk age lt 50"
               One_AR2       =  "1-Attributable risk age ge 50"

               PattrnNumber  =  "Relative risk covariate pattern #"

              &RR_Star1      =  "Relative risk age lt 50"
              &RR_Star2      =  "Relative risk age ge 50"

               One_AR_RR1    =  "(1-AR)*RelRsk age lt 50"
               One_AR_RR2    =  "(1-AR)*RelRsk age ge 50"

              &AbsRsk        =  "Abs risk(%) of BrCa in age interval [T1,T2)"
              &AbsRskAvg     =  "Abs risk(%) of BrCa in age interval [T1,T2) for an Average Women";
   run;




   proc  means  data=TmpFile  mean std n nmiss  maxdec=5;
   var   Error_Ind
        &AbsRsk
        &RR_Star1
        &RR_Star2;

   title4  "Quick check for errornous records on input file";
   title5  " ";
   title6  "IF MEAN OF  'Error_Ind'   EQUALS  0,   ERROR  FREE.    ERROR LISTING BELOW "
           "WILL BE EMPTY.";
   title7  "IF MEAN OF  'Error_Ind'   IS NOT  0,   ERRORS EXISTS.  CHECK ERROR LISTING "
           "BELOW.";
   title8  " ";
   title9  "(# of records with errors is the # listed under the NMiss column in the"
           " 'AbsRsk' line)";


***     proc contents data=tmpfile  position;
***     run;


   ***   Error listing file when errors detected as well as writing out a sas file which
         contains the projectd absolute risk as well as all the original input variables;
   data &Out_File (drop = Raw_Ind           -- NR_Cat
                          set_HyprP_Missing -- RacCat
                          II                -- LP2
                          iloop             -- Hj
                          Count_Error  key);      *** deleting unnecessary variables;

   set   TmpFile;
   by    Key;

         retain  Count_Error  0;

         file print;

         if (_N_ eq 1) then do;
            put " ";
            put "     ID                 #  Hypr  Hypr  Age  Age    #       "
                "        RR        RR                 Pat";
            put "      #    T1    T2  Biop  plas    RR  Men  1st  Rel   Race"
                "    Age<50   Age>=50      AbsRsk(%)    #";

            put " ";
         end;

         if (Error_Ind eq 1) then do;

           put &WID            7.0

               &T1             6.1
               &T2             6.1

              &N_Biop          6.0
              &HyperPlasia     6.0
               R_Hyp           6.2

              &AgeMen          5.0
              &Age1st          5.0
              &N_Rels          5.0

              "     "
              &Race            2.0

              &RR_Star1       10.2
              &RR_Star2       10.2
              &AbsRsk         12.0
               PattrnNumber    8.0;


            put
              "       "
               set_T1_Missing      6.1
               set_T2_Missing      6.1

               NB_Cat              6.0
               set_HyprP_Missing   6.0
               set_R_Hyp_Missing   6.2

               AM_Cat              5.0
               AF_Cat              5.0
               NR_Cat              5.0

              "     "
              &CharRace      $char2.;

            put " ";

            Count_Error = Count_Error + 1;
         end;

         if (last.Key and Count_Error eq 0) then do;
            put " ";
            put "      No errors detected for initial age, projection age "
                "and relative risk covaraites";
            put "      ---------------------------------------------------"
                "----------------------------";
            put "      |                                                  "
                "                           |";
            put "      |                                                  "
                "                           |";
            put " ";
            put "   ";
         end;

   title4  "Error listing for the input file";
   run;

%mend    BrCa_RAM;                   *** end of SAS macro to perform abs risk projection.
                                         End of restricted code area, where changes or
                                         modifications to the code should be avoided;

