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

APA_BrCa_RAM  SAS macro for projecting Asian-Pacific-American Women Absolute Risk of
              Breast Cancer with 95% CI based on the Gail Model RR estimates from the
              Asian American Breast Cancer Study (AABCS)

             "Projecting Individualized Absolute Invasive Breast Cancer Risk in Asian and
              Pacific Island American Women"  Matsuno,Costantino,Ziegler et al. JNCI 2011

NCI Asian-Pacific-American Women BrCa Risk Assessment Macro         Version 1.0  12/01/10

SAS macro to project for Asian-Pacific-American women absolute risk and 95% CI based on
AABCS data Gail RR model.  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 (around 380 lines of text comments) describes:

        o required input variables,
        o valid values for input variables,
        o restrictions  on input variables,
        o error indicator,
        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
     roughly 800 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 current age, projection age,  BrCa
relative risk covariates and race.  See the paragraph "Input data items ... " below,
for a detailed description of all required input data items.


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


Macro input structure:
---------------------
                       Required
        Macro          Macro                        "points" to SAS data files or
        name           parameters                               SAS variables

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

                       IDD         =,                unique identification #

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

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

                       NBiops      =,                # biopsies performed
                       AgeMen      =,                age at menarche
                       AgeFst      =,                age at first live birth
                       NumRel      =,                # 1st degree relatives with brca

                       HyperPlas   =,                atypical hyperplasia?

                       Race        =,                race of woman

                       RelRsk      =,                relative risk of brca
                       AbsRsk      =,                projected absolute risk of brca
                       se_AbsRsk   =,                se of absolute risk
                       Lo_95CI     =,                lower 95% confidence interval
                       Hi_95CI     =,                upper 95% confidence interval

                       Error_Ind   =);               error indicator for observation

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

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

To involke the sas macro in your sas program, an "#include" statement must be coded in
your sas program, which points to the directory where the sas macro is stored.

For example:

the statement: %include "APA_BrCa_RAM";              includes the sas macro  APA_BrCa_RAM
                                                     residing in your current directory

the statement: %include "c:\sas.macro\APA_BrCa_RAM"; includes the sas macro  APA_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 input values

IDD            Unique Identificaion #        positive integer values 1,2,3...9999999

T1             Current         age           ages between the interval [20,90)  e.g. 35.8
T2             BrCa projection age           ages between the interval (T1,90]  e.g. 58.9

NBiops         # of biopsies                 0,1,2 ...       99=unk,  99 recoded to 0

AgeMen         Age at menarche               integer age less than or equal to T1,
                                                             99=unk,  99 recoded to 0

AgeFst         Age first live birth          integer age greater equal to Age menarche
                                             98=nulliparous  99=unk,  99 recoded to 0

NumRel         # 1st degree relatives        0,1,2 ...       99=unk,  99 recoded to 0
               with BrCa

HyperPlasia    Did biopsy display            0=no,  1=yes,   99=Not applicable or unk
               atypical hyperplasia?         if # Biops=0 than Hyperplasia must be 99=Not applicable
                                             if # Biops>0 than Hyperplasia= 0,1 or 99=unk

Race           Race                          1=Chinese,
                                             2=Japanese,
                                             3=Filipino,
                                             4=Hawaiian,
                                             5=other Pacific Islander
                                             6=other Asian


in this document, depending on content, the following mathematical conventions
are adhered to:

   {} denotes a collection/set of numbers
      {a,b,c} is the set consiting of a,b and c
   [) represents an interval closed on the left and   open on the right
      [3,7) are all the numbers from 3 to 6.999...
   (] represents an interval   open on the left and closed on the right
      (3,7] are all the numbers from 3.000...1 to 7
   [] represents an interval closed on the left and closed on the right
      [3,7] are all the numbers from 3 to 7
   () represents an interval   open on the left and   open on the right
      (3,7) are all the numbers from 3.000...1 to 6.999....



this macro will categorize the raw values of NBiops, AgeMen, AgeFst, NumRel into
risk categories level numbers according to the rules outlined in the APA manuscript.

note that the program, being an analytical tool, will only make the most rudimentary
checks for logical consistency between the input variables.  It is the user's
responsibility to make sure that all input covariate values are logically
consistent and correct within each person.  As a final step, the program
will generate a missing projected Absolute Risk for records which it deems to
be in error.  The user should examine the output file for any records with a
missing Absolute Risk and rectify the error(s) for these records.

   e.g.  if NBiops equals zero than atypical hyperplasia must be 99 (not applicable)
    or   Projection Age in years must be greater than Current Age


Contacts:
Dr. Mitchell Gail     gailm@exchange.nih.gov      Scientific/Statistical issues
Mr. David    Pee      peed@imsweb.com             Technical/software problems



Recoding and checking of relative risk covariate values performed:

                                     input value                     recoded to

NBiops: # biopsies                     0          or 99(unk)                  0
                                       1                                      1
                                     [ 2, 98]                                 2


AgeMen: age at menarche              [14, 39]     or 99(unk)                  0
                                     [12, 14)                                 1
                                     [ 7, 12)                                 2


AgeFst: age first live birth         [AgeMen, 20) or 99(unk)                  0
                                     [20, 25)                                 1
                                     [25, 30)     or 98(nulliparious)         2
                                     [30, 98)                                 3


NumRel: # 1st degree rel with BrCa     0          or 99(unk)                  0
                                     [ 1, 98]                                 1


Consistency checks for T1, T2, AgeMen, AgeFst and Race :

20 =< T1 < T2 <= 90,                  OTHERWISE  abs risk = sas missing value of  "."
AgeMen <= AgeFst AgeMen ne 99(unk)    OTHERWISE  abs risk = sas missing value of  "."
Race = 1,2,3,4,5,6                    OTHERWISE  abs risk = sas missing value of  "."


Consistency patterns for  # of Biopsies and Hyperplasia:

NBiops = 0  or   99  then  Hyperplasia  MUST = 99(not applicable)
NBiops > 0 and < 99  then  Hyperplasia       =  0, 1 or 99(unk)

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) of the above two requirements is:

(A) # biopsies = 0 or   99  &  Hyperplasia  =99 (not applicbl) inflate  RR  by  1.00

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


Edit checking for AgeMen, AgeFst and NumRel:

AgeMen:                     positive integer values of 7,8,9 ... 39 or 99(unk)

AgeFst:  if (AgeMen <= 39)  positive integer values of AgeMen, AgeMen+1, AgeMen+2 ...
                                                               98(nulliparious), 99(unk)
         if (AgeMen  = 99)  positive integer values of 7,8,9...98(nulliparious), 99(unk)

NumRel:                     positive integer values of 0,1,2 ... 99(unk)




Following is a listing of the sample input raw data set  "APA_RR.fil".
Note that most of the following examples are high relative risk covariate patterns
thus resulting in large absolute risk of breast cancer.  especially for lifetime
risk i.e. prjection to age 90.

Also all relative risk covariates upon input are their RAW VALUES.
The sas macro  "APA_BrCa_RAM"  will recode the raw values to values
needed for abs risk projections.
(column heading included for clarity):

                            #   Age   Age     #   Hyper
   IDD      T1      T2   Biop   Men   Fst   Rel  Plasia  Race

     0    22.2    27.3      0    14    19     0      99     1
     0    22.2    90.3      0    14    19     0      99     1

     1    45.2    50.3      1    12    25     1      99     5
     1    45.2    90.3      1    12    25     1      99     5

     2    30.2    35.3      2    12    30     0      99     2
     2    30.2    90.3      2    12    30     0      99     2

     3    57.2    61.3      1     7    25     1      99     3
     3    57.2    90.3      1     7    25     1      99     3

     4    62.2    67.3      0     7    30     0       1     1
     4    62.2    90.3      0     7    30     0       1     1

     5    50.2    55.3      2    12    20     1       0     4
     5    50.2    90.0      2    12    20     1       0     4

     6    34.2    39.3      2     7    20     1      99     3
     6    34.2    90.0      2     7    20     1      99     3

     7    70.2    75.3      1     7    30     1       1     1
     7    70.2    90.0      1     7    30     1       1     1

     8    25.0    30.0      2    14    25     1       0     5
     8    25.0    90.0      2    14    25     1       0     5

     9    83.0    88.0      0    12    25     1       0     3
     9    83.0    90.0      0    12    25     1       0     3

    10    50.0    55.0      2     7    25     1      99     1
    10    50.0    90.0      2     7    25     1      99     1

    11    77.0    82.0      2    14    30     1      99     2
    11    77.0    90.0      2    14    30     1      99     2

    12    40.0    45.0      2    12    30     1      99     6
    12    40.0    90.0      2    12    30     1      99     6

    13    36.1    41.6      2     7    30     1      99     4
    13    36.1    90.0      2     7    30     1      99     4


Following is a listing of the consequence of applying the macro to the input file
Note the women with missing Absolute Risk (AbsRsk) projections.  This is due to violation
of edit/consistency requirements of the program.  Note the raw values for the RR
covaraties are listed, not the recoded values of 0,1,2 or 3.

APA_BrCa_RAM:   Asian-Pacific-American Women BrCa Abs Risk with 95% CI                 05/13/11
Listing of the first 100 input records with range errors on input fields:

                        #  Age  Age    #  Hypr    RR   Rel   Abs         SE  95%CI  95%CI
     ID    T1    T2  Biop  Men  Flb  Rel  Plas  Hypr  Risk  Risk(%)  AbsRsk  loLim  hiLim  Race

      1  45.2  90.3     1   12   25    1    99  1.00     .       .        .      .      .  5 oP
      2  30.2  90.3     2   12   30    0    99  1.00     .       .        .      .      .  2 Ja
      3  57.2  90.3     1    7   25    1    99  1.00     .       .        .      .      .  3 Fp
      4  62.2  67.3     0    7   30    0     1  1.00     .       .        .      .      .  1 Ch
      4  62.2  90.3     0    7   30    0     1  1.00     .       .        .      .      .  1 Ch
      9  83.0  88.0     0   12   25    1     0  0.93     .       .        .      .      .  3 Fp
      9  83.0  90.0     0   12   25    1     0  0.93     .       .        .      .      .  3 Fp
     14  22.2  90.3     0   14   19    0    99  1.00     .       .        .      .      .  1 Ch

In the above, examples of violation of editing and recoding rules are sprinkled throughout.
Note that any women who violates any of the editing/consistency rules for any of the variables
will receive a missing absolute risk estimate  i.e. AbsRsk=".".   For these instances, a
check of all variables for the affected women should be performed and any errors should be
corrected prior to re-obtaining absolute risk estimates.


********************************************************************************************
* note that it is still the user's responsibility to ensure that all input variables are   *
* correct and consistent e.g. one can't have current age > projection age or AgeMen<AgeFst *
********************************************************************************************


After the absolute risks have been generated, descriptive statistics by applying PROC
MEANS to the quantities Error_Ind, AbsRsk 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 "ABSOLUTE_RISK" listed under NMiss (# of missing).


APA_BrCa_example.sas:  Absolute risk projection of BrCa for Asian-Pacific-American women

Quick check for errornous records on input file

IF MEAN OF  Error_Ind   EQUALS  0   ==>   Input file is  ERROR  FREE
Otherwise bad records in input file

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

The MEANS Procedure

                                                                                              N
Variable         Label                                                       Mean     N    Miss
-----------------------------------------------------------------------------------------------
ERROR_IND        If mean not 0, implies Bad Records on input file          0.2857    28       0
ABSOLUTE_RISK    Absolute risk of BrCa (%)                                17.6685    20       8
RELTVRISK                                                                 12.3032    20       8
-----------------------------------------------------------------------------------------------


Since NMiss=8 for ABSOLUTE_RISK,  implies 8 records with editing errors are on input file

End of Readme section.




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

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


***     APA_BrCa_RAM  start of SAS macro which performs Asian-Pacific-American Women BrCa
                      Abs Risk projection with 95% confidence intervals

        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        Modification/change of any code from this point onward should be avoided,
        i.e. from the statement   "%macro    APA_BrCa_RAM"   to the statement
                                  "%mend     APA_BrCa_RAM".
        Any changes to these codes are done at the users risk, since changes may
        inadvertenly cause the macro to be fundamentally altered resulting in
        incorrect projections and/or abnormal termination
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

%macro  APA_BrCa_RAM (In_File         =,
                      Out_File        =,

                      IDD             =,

                      T1              =,
                      T2              =,

                      NBiops          =,
                      HyprPlas        =,

                      AgeMen          =,
                      AgeFst          =,
                      NumRel          =,

                      Race            =,

                      RelRsk          =,
                      AbsRsk          =,
                      se_AbsRsk       =,
                      Lo_95CI         =,
                      Hi_95CI         =,

                      Error_Ind       =);

   proc iml;

       ***
       Module for Eq 2.3 as stated by Benichou and Gail   Biometrics 46,813-826 1990
       from the document c:\ABSRSK_2.3eq                                   (04/17/93)

       This modules performs the integration for APA Women absolute risk of BrCa
       based on RR estimates of the Gail Model derived on APA Women in the AAPCS study;


       start  Eq2_3(Parms)  global(&T1, &T2, h1, h2); ***define integration module Eq2_3;

          One_AR_rr  = Parms;         *** (1-AR)*rr*rr_hyp = (1-AR)*exp(xstar*)*rr_Hypr;

          Strt_Intvl = floor(&T1) - 20 + 1;       *** T1=21 T2=23, Strt_Intvl=21-20+1= 2;
          End__Intvl =  ceil(&T2) - 20 + 0;       ***              End__Intvl=23-20+0= 3;
          Num__Intvl =  ceil(&T2) - floor(&T1);   ***              Num__Intvl=23-21  = 2;

                                        *** test case T1=35 T2=40  Strt_Intvl=35-20+1=16;
                                        ***                        End__Intvl=40-20+0=20;
                                        ***                        Num__Intvl=40-35  = 5;

          first_Intvl = 1 - (&T1-floor(&T1));***length of constant hazard for  1st intvl;
           last_Intvl = 1 - (ceil(&T2)-&T2); ***length of constant hazard for last intvl;

          *** Lngth_vec is the length of integeration domain for each year in the [T1,T2)
              it is usually of length 1 except maybe at the end points represented by
              first_Intvl and last_Intvl which could be fractions of 1;

          if      (Num__Intvl  > 2) then
             Lngth_vec = first_Intvl // j(Num__Intvl-2, 1) //
                         last_Intvl;                  *** > 2 integration 5 yr intervals;

          else if (Num__Intvl  = 2) then
             Lngth_vec = first_Intvl // last_Intvl;   *** = 2 integration 5 yr intervals;

          else if (Num__Intvl  = 1) then
             Lngth_vec = &T2 - &T1;                   *** = 1 integration 5 yr intervals;


          PI_j    = j(Num__Intvl,1);                  *** holds each age interval part of ;

          G_vec   = ((h1[ 1:30]#ONE_AR_rr[1])//(h1[31:70]#ONE_AR_rr[2])) + h2;

          &AbsRsk = 0;
          Cum_G   = 0;
          j_intvl = 1;

          do while (j_intvl <= Num__Intvl);

             intvl_indx    = Strt_Intvl + (j_intvl-1);

             Gj            = G_vec[intvl_indx];
             h1_j          = h1[intvl_indx];

             if      (intvl_indx <= 30) then
                Tmp1_AR_rr = ONE_AR_rr[1];                                 *** age < 50;
             else if (intvl_indx  > 30) then
                Tmp1_AR_rr = ONE_AR_rr[2];                                 *** age  50;

             PI_j[j_intvl] = ((Tmp1_AR_rr*h1_j*exp(-Cum_G))/Gj)*(1-exp(-Gj));

             &AbsRsk       = &AbsRsk + Lngth_vec[j_intvl]*PI_j[j_intvl];

             Cum_G         = Cum_G + Gj;
             j_intvl       = j_intvl + 1;
          end;

          return(&AbsRsk);                                          *** returns abs risk;

       finish  Eq2_3;                                      *** end of integration module;


       *** row1    AgeGE50 Ind      set to zero by default  (not in the APA RR model)

           row2    # Biospy         0,1,2
           row3    Age menarche     0,1,2
           row4    Age 1st Birth    0,1,2,3
           row5    # Rel with BrCa  0,1          (also includes 2 in original gail model)

           row6    AgeGE50*#Biop    0,1,2       (not in the APA RR model)
           row7    Age1stBrth*#Rel  0,1,2,3      (not in the APA RR model);

       BETA        ={0.00000000000000,

                     0.55263612260619,
                     0.07499257592975,
                     0.27638268294593,
                     0.79185633720481,

                     0.00000000000000,
                     0.00000000000000};


       *** row1  1-AR age lt 50
           row2  1-AR age ge 50;

       ONE_AR      ={0.47519806426735,
                     0.50316401683903};


       *** SEER18 incidence 1998:02 - chinese  Jan052010;

       h1c= 0.000004059636*j(5,1) //
            0.000045944465*j(5,1) //
            0.000188279352*j(5,1) //
            0.000492930493*j(5,1) //
            0.000913603501*j(5,1) //
            0.001471537353*j(5,1) //

            0.001421275482*j(5,1) //
            0.001970946494*j(5,1) //
            0.001674745804*j(5,1) //
            0.001821581075*j(5,1) //
            0.001834477198*j(5,1) //
            0.001919911972*j(5,1) //
            0.002233371071*j(5,1) //
            0.002247315779*j(5,1);


       *** NCHS mortality 1998:02,    chinese  Jan052010;

       h2c= 0.000210649076*j(5,1) //
            0.000192644865*j(5,1) //
            0.000244435215*j(5,1) //
            0.000317895949*j(5,1) //
            0.000473261994*j(5,1) //
            0.000800271380*j(5,1) //

            0.001217480226*j(5,1) //
            0.002099836508*j(5,1) //
            0.003436889186*j(5,1) //
            0.006097405623*j(5,1) //
            0.010664526765*j(5,1) //
            0.020148678452*j(5,1) //
            0.037990796590*j(5,1) //
            0.098333900733*j(5,1);



       *** SEER18 incidence 1998:02 - japanese  Jan052010;

       h1j= 0.000000000001*j(5,1) //
            0.000099483924*j(5,1) //
            0.000287041681*j(5,1) //
            0.000545285759*j(5,1) //
            0.001152211095*j(5,1) //
            0.001859245108*j(5,1) //

            0.002606291272*j(5,1) //
            0.003221751682*j(5,1) //
            0.004006961859*j(5,1) //
            0.003521715275*j(5,1) //
            0.003593038294*j(5,1) //
            0.003589303081*j(5,1) //
            0.003538507159*j(5,1) //
            0.002051572909*j(5,1);


       *** NCHS mortality 1998:02,    japanese  Jan052010;

       h2j= 0.000173593803*j(5,1) //
            0.000295805882*j(5,1) //
            0.000228322534*j(5,1) //
            0.000363242389*j(5,1) //
            0.000590633044*j(5,1) //
            0.001086079485*j(5,1) //

            0.001859999966*j(5,1) //
            0.003216600974*j(5,1) //
            0.004719402141*j(5,1) //
            0.008535331402*j(5,1) //
            0.012433511681*j(5,1) //
            0.020230197885*j(5,1) //
            0.037725498348*j(5,1) //
            0.106149118663*j(5,1);



       *** SEER18 incidence 1998:02 - filipino  Jan052010;

       h1f= 0.000007500161*j(5,1) //
            0.000081073945*j(5,1) //
            0.000227492565*j(5,1) //
            0.000549786433*j(5,1) //
            0.001129400541*j(5,1) //
            0.001813873795*j(5,1) //

            0.002223665639*j(5,1) //
            0.002680309266*j(5,1) //
            0.002891219230*j(5,1) //
            0.002534421279*j(5,1) //
            0.002457159409*j(5,1) //
            0.002286616920*j(5,1) //
            0.001814802825*j(5,1) //
            0.001750879130*j(5,1);


       *** NCHS mortality 1998:02,    filipino  Jan052010;

       h2f= 0.000229120979*j(5,1) //
            0.000262988494*j(5,1) //
            0.000314844090*j(5,1) //
            0.000394471908*j(5,1) //
            0.000647622610*j(5,1) //
            0.001170202327*j(5,1) //

            0.001809380379*j(5,1) //
            0.002614170568*j(5,1) //
            0.004483330681*j(5,1) //
            0.007393665092*j(5,1) //
            0.012233059675*j(5,1) //
            0.021127058106*j(5,1) //
            0.037936954809*j(5,1) //
            0.085138518334*j(5,1);



       *** SEER18 incidence 1998:02 - hawaiian  Jan052010;

       h1h= 0.000045080582*j(5,1) //
            0.000098570724*j(5,1) //
            0.000339970860*j(5,1) //
            0.000852591429*j(5,1) //
            0.001668562761*j(5,1) //
            0.002552703284*j(5,1) //

            0.003321774046*j(5,1) //
            0.005373001776*j(5,1) //
            0.005237808549*j(5,1) //
            0.005581732512*j(5,1) //
            0.005677419355*j(5,1) //
            0.006513409962*j(5,1) //
            0.003889457523*j(5,1) //
            0.002949061662*j(5,1);


       *** NCHS mortality 1998:02,    hawaiian  Jan052010;

       h2h= 0.000563507269*j(5,1) //
            0.000369640217*j(5,1) //
            0.001019912579*j(5,1) //
            0.001234013911*j(5,1) //
            0.002098344078*j(5,1) //
            0.002982934175*j(5,1) //

            0.005402445702*j(5,1) //
            0.009591474245*j(5,1) //
            0.016315472607*j(5,1) //
            0.020152229069*j(5,1) //
            0.027354838710*j(5,1) //
            0.050446998723*j(5,1) //
            0.072262026612*j(5,1) //
            0.145844504021*j(5,1);



       *** SEER18 incidence 1998:02 - other pacific islander  Jan052010;

       h1o= 0.000000000001*j(5,1) //
            0.000071525212*j(5,1) //
            0.000288799028*j(5,1) //
            0.000602250698*j(5,1) //
            0.000755579402*j(5,1) //
            0.000766406354*j(5,1) //

            0.001893124938*j(5,1) //
            0.002365580107*j(5,1) //
            0.002843933070*j(5,1) //
            0.002920921732*j(5,1) //
            0.002330395655*j(5,1) //
            0.002036291235*j(5,1) //
            0.001482683983*j(5,1) //
            0.001012248203*j(5,1);


       *** NCHS mortality 1998:02,    other pacific islander  Jan052010;

       h2o= 0.000465500812*j(5,1) //
            0.000600466920*j(5,1) //
            0.000851057138*j(5,1) //
            0.001478265376*j(5,1) //
            0.001931486788*j(5,1) //
            0.003866623959*j(5,1) //

            0.004924932309*j(5,1) //
            0.008177071806*j(5,1) //
            0.008638202890*j(5,1) //
            0.018974658371*j(5,1) //
            0.029257567105*j(5,1) //
            0.038408980974*j(5,1) //
            0.052869579345*j(5,1) //
            0.074745721133*j(5,1);



       *** SEER18 incidence 1998:02 - other asian  Jan052010;

       h1a= 0.000012355409*j(5,1) //
            0.000059526456*j(5,1) //
            0.000184320831*j(5,1) //
            0.000454677273*j(5,1) //
            0.000791265338*j(5,1) //
            0.001048462801*j(5,1) //

            0.001372467817*j(5,1) //
            0.001495473711*j(5,1) //
            0.001646746198*j(5,1) //
            0.001478363563*j(5,1) //
            0.001216010125*j(5,1) //
            0.001067663700*j(5,1) //
            0.001376104012*j(5,1) //
            0.000661576644*j(5,1);


       *** NCHS mortality 1998:02,    other asian Jan052010;

       h2a= 0.000212632332*j(5,1) //
            0.000242170741*j(5,1) //
            0.000301552711*j(5,1) //
            0.000369053354*j(5,1) //
            0.000543002943*j(5,1) //
            0.000893862331*j(5,1) //

            0.001515172239*j(5,1) //
            0.002574669551*j(5,1) //
            0.004324370426*j(5,1) //
            0.007419621918*j(5,1) //
            0.013251765130*j(5,1) //
            0.022291427490*j(5,1) //
            0.041746550635*j(5,1) //
            0.087485802065*j(5,1);

       h1_prnt = h1c || h1j || h1f || h1h || h1o || h1a;
       h2_prnt = h2c || h2j || h2f || h2h || h2o || h2a;


       file print;
       current_date = date(  );

       put "APA_BrCa_RAM:   Asian-Pacific-American Women BrCa Abs Risk with"
           " 95% CI                   "  current_date mmddyy8.;
       put " ";
       put "Constants used for Asian-Pacific-American Women Breast Cancer"
           " Absolute Risk Projection";
       put " ";
       put " ";
       put  "SEER18 Asian-Pacific female 5yr age interval BrCa incidences  1998-2002       (01/05/10 NCI e-mail)";
       put  " ";
       put  "5yrAge";
       put  "Intrvl          Chinese       Japanese       Filipino       Hawaiian     Otr Pacifc    Other Asian";
       put  " ";

       put "[20:25) " (h1_prnt[ 1, 1]) 15.11 (h1_prnt[ 1, 2]) 15.11 (h1_prnt[ 1, 3]) 15.11 (h1_prnt[ 1, 4]) 15.11 (h1_prnt[ 1, 5]) 15.11 (h1_prnt[ 1, 6]) 15.11;
       put "[25:30) " (h1_prnt[ 6, 1]) 15.11 (h1_prnt[ 6, 2]) 15.11 (h1_prnt[ 6, 3]) 15.11 (h1_prnt[ 6, 4]) 15.11 (h1_prnt[ 6, 5]) 15.11 (h1_prnt[ 6, 6]) 15.11;
       put "[30:35) " (h1_prnt[11, 1]) 15.11 (h1_prnt[11, 2]) 15.11 (h1_prnt[11, 3]) 15.11 (h1_prnt[11, 4]) 15.11 (h1_prnt[11, 5]) 15.11 (h1_prnt[11, 6]) 15.11;
       put "[35:40) " (h1_prnt[16, 1]) 15.11 (h1_prnt[16, 2]) 15.11 (h1_prnt[16, 3]) 15.11 (h1_prnt[16, 4]) 15.11 (h1_prnt[16, 5]) 15.11 (h1_prnt[16, 6]) 15.11;
       put "[40:45) " (h1_prnt[21, 1]) 15.11 (h1_prnt[21, 2]) 15.11 (h1_prnt[21, 3]) 15.11 (h1_prnt[21, 4]) 15.11 (h1_prnt[21, 5]) 15.11 (h1_prnt[21, 6]) 15.11;
       put "[45:50) " (h1_prnt[26, 1]) 15.11 (h1_prnt[26, 2]) 15.11 (h1_prnt[26, 3]) 15.11 (h1_prnt[26, 4]) 15.11 (h1_prnt[26, 5]) 15.11 (h1_prnt[26, 6]) 15.11;
       put "[50:55) " (h1_prnt[31, 1]) 15.11 (h1_prnt[31, 2]) 15.11 (h1_prnt[31, 3]) 15.11 (h1_prnt[31, 4]) 15.11 (h1_prnt[31, 5]) 15.11 (h1_prnt[31, 6]) 15.11;
       put "[55:60) " (h1_prnt[36, 1]) 15.11 (h1_prnt[36, 2]) 15.11 (h1_prnt[36, 3]) 15.11 (h1_prnt[36, 4]) 15.11 (h1_prnt[36, 5]) 15.11 (h1_prnt[36, 6]) 15.11;
       put "[60:65) " (h1_prnt[41, 1]) 15.11 (h1_prnt[41, 2]) 15.11 (h1_prnt[41, 3]) 15.11 (h1_prnt[41, 4]) 15.11 (h1_prnt[41, 5]) 15.11 (h1_prnt[41, 6]) 15.11;
       put "[65:70) " (h1_prnt[46, 1]) 15.11 (h1_prnt[46, 2]) 15.11 (h1_prnt[46, 3]) 15.11 (h1_prnt[46, 4]) 15.11 (h1_prnt[46, 5]) 15.11 (h1_prnt[46, 6]) 15.11;
       put "[70:75) " (h1_prnt[51, 1]) 15.11 (h1_prnt[51, 2]) 15.11 (h1_prnt[51, 3]) 15.11 (h1_prnt[51, 4]) 15.11 (h1_prnt[51, 5]) 15.11 (h1_prnt[51, 6]) 15.11;
       put "[75:80) " (h1_prnt[56, 1]) 15.11 (h1_prnt[56, 2]) 15.11 (h1_prnt[56, 3]) 15.11 (h1_prnt[56, 4]) 15.11 (h1_prnt[56, 5]) 15.11 (h1_prnt[56, 6]) 15.11;
       put "[80:85) " (h1_prnt[61, 1]) 15.11 (h1_prnt[61, 2]) 15.11 (h1_prnt[61, 3]) 15.11 (h1_prnt[61, 4]) 15.11 (h1_prnt[61, 5]) 15.11 (h1_prnt[61, 6]) 15.11;
       put "[85:90) " (h1_prnt[66, 1]) 15.11 (h1_prnt[66, 2]) 15.11 (h1_prnt[66, 3]) 15.11 (h1_prnt[66, 4]) 15.11 (h1_prnt[66, 5]) 15.11 (h1_prnt[66, 6]) 15.11;
       put " ";
       put " ";


       put "NCHS Asian-Pacific female 5yr age interval non-BrCa mortality rates  1998-2002    (01/05/10 e-mail)";
       put " ";
       put "5yrAge";
       put "Intrvl          Chinese       Japanese       Filipino       Hawaiian     Otr Pacifc    Other Asian";
       put " ";
       put "[20:25) " (h2_prnt[ 1, 1]) 15.11 (h2_prnt[ 1, 2]) 15.11 (h2_prnt[ 1, 3]) 15.11 (h2_prnt[ 1, 4]) 15.11 (h2_prnt[ 1, 5]) 15.11 (h2_prnt[ 1, 6]) 15.11;
       put "[25:30) " (h2_prnt[ 6, 1]) 15.11 (h2_prnt[ 6, 2]) 15.11 (h2_prnt[ 6, 3]) 15.11 (h2_prnt[ 6, 4]) 15.11 (h2_prnt[ 6, 5]) 15.11 (h2_prnt[ 6, 6]) 15.11;
       put "[30:35) " (h2_prnt[11, 1]) 15.11 (h2_prnt[11, 2]) 15.11 (h2_prnt[11, 3]) 15.11 (h2_prnt[11, 4]) 15.11 (h2_prnt[11, 5]) 15.11 (h2_prnt[11, 6]) 15.11;
       put "[35:40) " (h2_prnt[16, 1]) 15.11 (h2_prnt[16, 2]) 15.11 (h2_prnt[16, 3]) 15.11 (h2_prnt[16, 4]) 15.11 (h2_prnt[16, 5]) 15.11 (h2_prnt[16, 6]) 15.11;
       put "[40:45) " (h2_prnt[21, 1]) 15.11 (h2_prnt[21, 2]) 15.11 (h2_prnt[21, 3]) 15.11 (h2_prnt[21, 4]) 15.11 (h2_prnt[21, 5]) 15.11 (h2_prnt[21, 6]) 15.11;
       put "[45:50) " (h2_prnt[26, 1]) 15.11 (h2_prnt[26, 2]) 15.11 (h2_prnt[26, 3]) 15.11 (h2_prnt[26, 4]) 15.11 (h2_prnt[26, 5]) 15.11 (h2_prnt[26, 6]) 15.11;
       put "[50:55) " (h2_prnt[31, 1]) 15.11 (h2_prnt[31, 2]) 15.11 (h2_prnt[31, 3]) 15.11 (h2_prnt[31, 4]) 15.11 (h2_prnt[31, 5]) 15.11 (h2_prnt[31, 6]) 15.11;
       put "[55:60) " (h2_prnt[36, 1]) 15.11 (h2_prnt[36, 2]) 15.11 (h2_prnt[36, 3]) 15.11 (h2_prnt[36, 4]) 15.11 (h2_prnt[36, 5]) 15.11 (h2_prnt[36, 6]) 15.11;
       put "[60:65) " (h2_prnt[41, 1]) 15.11 (h2_prnt[41, 2]) 15.11 (h2_prnt[41, 3]) 15.11 (h2_prnt[41, 4]) 15.11 (h2_prnt[41, 5]) 15.11 (h2_prnt[41, 6]) 15.11;
       put "[65:70) " (h2_prnt[46, 1]) 15.11 (h2_prnt[46, 2]) 15.11 (h2_prnt[46, 3]) 15.11 (h2_prnt[46, 4]) 15.11 (h2_prnt[46, 5]) 15.11 (h2_prnt[46, 6]) 15.11;
       put "[70:75) " (h2_prnt[51, 1]) 15.11 (h2_prnt[51, 2]) 15.11 (h2_prnt[51, 3]) 15.11 (h2_prnt[51, 4]) 15.11 (h2_prnt[51, 5]) 15.11 (h2_prnt[51, 6]) 15.11;
       put "[75:80) " (h2_prnt[56, 1]) 15.11 (h2_prnt[56, 2]) 15.11 (h2_prnt[56, 3]) 15.11 (h2_prnt[56, 4]) 15.11 (h2_prnt[56, 5]) 15.11 (h2_prnt[56, 6]) 15.11;
       put "[80:85) " (h2_prnt[61, 1]) 15.11 (h2_prnt[61, 2]) 15.11 (h2_prnt[61, 3]) 15.11 (h2_prnt[61, 4]) 15.11 (h2_prnt[61, 5]) 15.11 (h2_prnt[61, 6]) 15.11;
       put "[85:90) " (h2_prnt[66, 1]) 15.11 (h2_prnt[66, 2]) 15.11 (h2_prnt[66, 3]) 15.11 (h2_prnt[66, 4]) 15.11 (h2_prnt[66, 5]) 15.11 (h2_prnt[66, 6]) 15.11;
       put " ";
       put " ";


       put "                  ln   RR                                   1-AR";
       put " ";
       put "# Biops  "   (Beta[2]) 16.10  "             Age lt 50 " (ONE_AR[1]) 16.10;
       put "Age Men  "   (Beta[3]) 16.10  "             Age ge 50 " (ONE_AR[2]) 16.10;
       put "Age Fst  "   (Beta[4]) 16.10;
       put "# Reltv  "   (Beta[5]) 16.10;
       put " ";


       *** following matrix is from APA_BrCa_AbsRsk.gau,  row order is:

              RelRisk Row Order ID = 24*NBiops      3 levels
                                      8*AgeMen      3 levels
                                      2*AgeFlb      4 levels
                                      1*NumRel + 1  2 levels;


       ***      variance           variance         covariance             Age LT             Age GE
             (1-AR1)*RR1        (1-AR2)*RR2        (1-AR1)*RR1                 50                 50
                                                   (1-AR2)*RR2                RR1                RR2;
       ARrrstar_CovARrrstar =

       {0.00582996299883   0.00511738157398   0.00527367935818   1.00000000000000   1.00000000000000
        0.07828301997334   0.07498417459409   0.07573577238172   2.20749047180781   2.20749047180781
        0.00413682678169   0.00312297132567   0.00326625153040   1.31835227843944   1.31835227843944
        0.10678204216162   0.10213597015042   0.10282043402255   2.91025009314118   2.91025009314118
        0.00368248769562   0.00314851473238   0.00274359542278   1.73805273006646   1.73805273006646
        0.16839697233797   0.16629415143918   0.16430354295602   3.83673484112125   3.83673484112125
        0.01232054339551   0.01498306363289   0.01239389522420   2.29136577673100   2.29136577673100
        0.32135194210069   0.33517232835782   0.32253619619263   5.05816811956018   5.05816811956018
        0.00517305311037   0.00507279497668   0.00486773067171   1.07787614862668   1.07787614862668
        0.08129811983420   0.08078656189124   0.07989115270490   2.37940132788229   2.37940132788229
        0.00243957337243   0.00257657212272   0.00204516868408   1.42102047641751   1.42102047641751
        0.10930579624239   0.10992503103224   0.10752034420322   3.13688916193544   3.13688916193544
        0.00088582986409   0.00263818031088   0.00090988670773   1.87340558279412   1.87340558279412
        0.17351345819379   0.18195405004821   0.17386082812027   4.13552497384957   4.13552497384957
        0.00967064380904   0.01703973654525   0.01176731349735   2.46980851851779   2.46980851851779
        0.34098898414106   0.37670189933845   0.35159377274744   5.45207877181778   5.45207877181778
        0.00811261271577   0.00932153053866   0.00838718920303   1.16181699177828   1.16181699177828
        0.10254472487545   0.10814806471215   0.10384992377431   2.56469993933497   2.56469993933497
        0.00697039442106   0.00949155969931   0.00763429154237   1.53168407824055   1.53168407824055
        0.14340430402450   0.15518013482096   0.14657771372799   3.38117800853575   3.38117800853575
        0.00905533727135   0.01529799849343   0.01108288288972   2.01929919439784   2.01929919439784
        0.23419507457399   0.26371257625218   0.24395974488396   4.45758373136242   4.45758373136242
        0.02664100183531   0.04269046063300   0.03263801441252   2.66214769378531   2.66214769378531
        0.45992768647320   0.53653789164053   0.48893601455204   5.87666566857622   5.87666566857622
        0.02428572587429   0.02342443162659   0.02322614446259   1.73782811293638   1.73782811293638
        0.27290176497112   0.26970586112829   0.26846395890489   3.83623900094680   3.83623900094680
        0.02319240357432   0.02226368978410   0.02158803102223   2.29106965222578   2.29106965222578
        0.38146528622807   0.37865797379564   0.37489760689151   5.05751442753645   5.05751442753645
        0.02813611267246   0.03003955028397   0.02698876044044   3.02043689607531   3.02043689607531
        0.60337229657196   0.61559640923667   0.59993617318246   6.66758566878300   6.66758566878300
        0.06403413906992   0.07785331338654   0.06702807939822   3.98199986382343   3.98199986382343
        1.12188808411632   1.19428812282337   1.14019100147781   8.79022675813021   8.79022675813021
        0.02310908848815   0.02427276196465   0.02289171993219   1.87316347334703   1.87316347334703
        0.28657832698074   0.29273364671369   0.28603249769735   4.13499051955200   4.13499051955200
        0.01932252495965   0.02215702973791   0.01929406430461   2.46948933297659   2.46948933297659
        0.39631437117572   0.41094409037258   0.39705571118040   5.45137417277685   5.45137417277685
        0.02161714022726   0.03089422929783   0.02360248565192   3.25565688871158   3.25565688871158
        0.63013927815379   0.67672285730395   0.64132204353080   7.18683156130626   7.18683156130626
        0.05893612383537   0.08773038693522   0.06840469056619   4.29210267704996   4.29210267704996
        1.19869263188530   1.34132284434870   1.24741716054153   9.47477576360857   9.47477576360857
        0.03288032651451   0.03819656754501   0.03450961429743   2.01903823039947   2.01903823039947
        0.35583884770778   0.38151985095668   0.36399200903276   4.45700765582253   4.45700765582253
        0.03438802451947   0.04474762418296   0.03771131941094   2.66180365130347   2.66180365130347
        0.50731532151023   0.55737710078325   0.52386676837237   5.87590619807566   5.87590619807566
        0.04839463196662   0.07176118505446   0.05668362046551   3.50919490845435   3.50919490845435
        0.82589498489932   0.93897817560913   0.86688295082743   7.74651432412945   7.74651432412945
        0.11332987413518   0.16919525804744   0.13498701439379   4.62635510304886   4.62635510304886
        1.57709222102811   1.84787633695345   1.68361978067338  10.21263480917981  10.21263480917981
        0.14815370353884   0.15607099683261   0.15004298051690   3.02004655011201   3.02004655011201
        1.20061369734746   1.24365897912328   1.21271104609928   6.66672398378832   6.66672398378832
        0.19731887404760   0.21246294821566   0.20115736942940   3.98148525033334   3.98148525033334
        1.79292801632230   1.87441845984069   1.81662556442474   8.78909075375417   8.78909075375417
        0.30141259993969   0.33777870997290   0.31275947903573   5.24900015134997   5.24900015134997
        2.91284343166275   3.10331264583464   2.97675857580399  11.58711782062281  11.58711782062281
        0.56127410910536   0.65521847911955   0.59557161568143   6.92003130906118   6.92003130906118
        5.24329945800418   5.72393350526005   5.42531993127284  15.27590317936429  15.27590317936429
        0.15587967096024   0.17151443951028   0.16108738739859   3.25523614410803   3.25523614410803
        1.29880640108257   1.37813238148625   1.32654710511052   7.18590277160286   7.18590277160286
        0.20479154931084   0.23403119332399   0.21471006472268   4.29154798744322   4.29154798744322
        1.93448310101729   2.08234498078875   1.98688676558284   9.47355129158690   9.47355129158690
        0.31425347178805   0.37754046982883   0.33731121916200   5.65777206727796   5.65777206727796
        3.15800427641213   3.47561468061835   3.27737532763953  12.48947793017647  12.48947793017647
        0.60107155015465   0.74816434376875   0.65875429739627   7.45893669578690   7.45893669578690
        5.75431325631771   6.48687826713742   6.04747414329314  16.46553168576721  16.46553168576721
        0.19836027866617   0.22838100501421   0.21003742925531   3.50874139788152   3.50874139788152
        1.57341949076664   1.72097553114214   1.63191199521108   7.74551320386107   7.74551320386107
        0.27231803116753   0.32742797548111   0.29387973576472   4.62575721635188   4.62575721635188
        2.38093857957467   2.65159919064725   2.48872867478651  10.21131497999299  10.21131497999299
        0.43251110353738   0.54370492450274   0.47719644381875   6.09837756568517   6.09837756568517
        3.93814165829183   4.48350189367030   4.16054572299553  13.46211036973651  13.46211036973651
        0.82876639246666   1.06673522755465   0.92766947908653   8.03980995850499   8.03980995850499
        7.21789508343087   8.38335464614092   7.70780581184940  17.74780387854531  17.74780387854531};


       N_Rows = ncol(ARrrstar_CovARrrstar)/5;  *** 72 covariate patterns in order of
                                                   #Biop(3),AgeMen(3),Age1st(4),#Rel(2)
                                                   72 =  3  *      3  *      4  *    2;

       ARrrstar_CovARrrstar = shape(ARrrstar_CovARrrstar, N_Rows, 5);

       *** row 73 of missing values to be used with records with editing errors;
       ARrrstar_CovARrrstar = ARrrstar_CovARrrstar // (j(1,5,.));

       RRofXStar   = ARrrstar_CovARrrstar[1:73,4:5];
       CovARrrstar = ARrrstar_CovARrrstar[1:73,1:3];

       charRace = {" Ch"  " Ja"  " Fp"  " Hw"  " oP"  " oA"  " ??"};


       *** column heading for listing output;
       file print;
       _page_ = "";
       put _page_;
       put "APA_BrCa_RAM:   Asian-Pacific-American Women BrCa Abs Risk with 95% CI                 "
            current_date mmddyy8.;

       put "Listing of the first 100 input records with range errors on input fields: ";
       put " ";
       put "                        #  Age  Age    #  Hypr    RR   Rel   Abs         SE  95%CI  95%CI";
       put "     ID    T1    T2  Biop  Men  Flb  Rel  Plas  Hypr  Risk  Risk(%)  AbsRsk  loLim  hiLim  Race";
       put " ";

       use     &In_File;                                      *** open SAS input dataset;

       *** sas file with asian-pacific-american rr covariates, abs risk and 95%ci;
       create  &Out_File  var {&NBiops  &AgeMen     &AgeFst   &NumRel  &HyprPlas  &T1  &T2   &IDD
                               &RelRsk  &AbsRsk  &se_AbsRsk  &Lo_95ci  &Hi_95ci   &Error_Ind &Race};

       &AbsRsk    = j(1,1,.);
       &se_AbsRsk = j(1,1,.);
       &Lo_95ci   = j(1,1,.);
       &Hi_95ci   = j(1,1,.);


       irows = 1;
       setin   &In_File  point 0;

       do data; ***do data will not read past end of file  p96 SAS/IML Users Guide Ver8;

          read  next  var {&IDD  &T1  &T2  &NBiops  &AgeMen  &AgeFst  &NumRel  &HyprPlas  &Race};


          &Error_Ind = 0;   *** edit error indicator  Error_Ind=1 ==>;
                            *** abs risk will not be calculated;

          *** check for race eq integer 1,2...9999999;
          if (int(&IDD) ^= &IDD   | (&IDD  < 1 | &IDD  > 9999999)) then &Error_Ind = 1;

          IIDD = &IDD;


          *** check for race eq integer 1,2,3,4,5,6  i.e. 1=c 2=j 3=f 4=h 5=op 6=oa;
          RaceIndx = &Race;
          if (int(&Race) ^= &Race |
                 (&Race  ^= 1 &
                  &Race  ^= 2 &
                  &Race  ^= 3 &
                  &Race  ^= 4 &
                  &Race  ^= 5 &
                  &Race  ^= 6)) then do;

                 &Error_Ind = 1;
                  RaceIndx  = 7;
          end;


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

          if (&T1 < 20) then do;
             set_T1_Missing = .;
             &Error_Ind     = 1;
          end;

          if (&T1 > 90) then do;
             set_T1_Missing = .;
             &Error_Ind     = 1;
          end;

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

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


          *** rr covariates are in raw/original format;
          *** codes to test for consistency of N_Biop (#biopsies) and HyprPlas;
          NB_Cat = -1;                             ***set NB_Cat to default value -1;

          if      ((&NBiops = 0  |  &NBiops = 99)  &  &HyprPlas ^= 99) then do;
             NB_Cat             = .a;
             &Error_Ind         =  1;                            *** error condition;
          end;
          else if ((&NBiops > 0  &  &NBiops < 99)  &  (&HyprPlas ^=  0  &
                                                       &HyprPlas ^=  1  &
                                                       &HyprPlas ^= 99)) then do;
             NB_Cat             = .b;
             &Error_Ind         =  1;                            *** error condition;
          end;

          *** editing and recoding for NBiops;
          if (NB_Cat = -1) then do;          *** NB_Cat=-1 implies no error violations;
             if      (int(&NBiops)   ^=  abs(&NBiops))  then  NB_Cat=.;  *** + integer;
             else if (&NBiops  =  0  |  &NBiops  = 99)  then  NB_Cat=0;
             else if (&NBiops  =  1                  )  then  NB_Cat=1;
             else if (&NBiops >=  2  &  &NBiops ^= 99)  then  NB_Cat=2;
             else                                             NB_Cat=.;
          end;


          *** editing and recoding for AgeMen;
          *** code to test for AgeMen <= T1;
          AM_Cat = -1;
          if (&AgeMen ^= 99 & &AgeMen > &T1) then AM_Cat = .;

          if (AM_Cat = -1) then do;           *** AM_Cat=-1 implies no error violations;
             if      (int(&AgeMen)    ^=  abs(&AgeMen))                   then AM_Cat=.;  *** + integer;
             else if ((&AgeMen >= 14  &  &AgeMen <= 39) |  &AgeMen  = 99) then AM_Cat=0;
             else if ( &AgeMen >= 12  &  &AgeMen <  14)                   then AM_Cat=1;
             else if ( &AgeMen >=  7  &  &AgeMen <  12)                   then AM_Cat=2;
             else                                                              AM_Cat=.;
          end;

          *** editing and recoding for AgeFst;
          *** codes to test that AgeMen <= AgeFst;
          AF_Cat = -1;                              *** set AF_Cat to default value -1;
          if     (&AgeMen ^= 99  &  (&AgeMen > &AgeFst)) then  AF_Cat = .;   *** error;

          if (AF_Cat = -1) then do;          *** AF_Cat=-1 implies no error violations;
             if      (int(&AgeFst)    ^= abs(&AgeFst))                   then AF_Cat=.;  *** + integer;
             else if ((                  &AgeFst < 20)  |  &AgeFst = 99) then AF_Cat=0;
             else if ( &AgeFst >= 20  &  &AgeFst < 25                  ) then AF_Cat=1;
             else if ((&AgeFst >= 25  &  &AgeFst < 30)  |  &AgeFst = 98) then AF_Cat=2;
             else if ( &AgeFst >= 30  &  &AgeFst < 98                  ) then AF_Cat=3;
             else                                                             AF_Cat=.;
          end;


          *** editing and recoding for NumRel;
          if      (int(&NumRel)   ^= abs(&NumRel))                       then NR_Cat=.;  *** + integer;
          else if (&NumRel  =  0  |  &NumRel = 99)                       then NR_Cat=0;
          else if (&NumRel >=  1  &  &NumRel < 99)                       then NR_Cat=1;
          else                                                                 NR_Cat=.;


          *** setting RR multiplicative factor for atypical hyperplasia;
          if      (NB_Cat  =  0)         then  rrHypr = 1.00;           *** # Biopsy=0;
          else if (NB_Cat  >  0) then do;                               *** # Biopsy>0;
             if      (&HyprPlas  =  0)   then  rrHypr = 0.93;
             else if (&HyprPlas  =  1)   then  rrHypr = 1.82;
             else if (&HyprPlas  = 99)   then  rrHypr = 1.00;
             else                              rrHypr =  .  ;           *** HP ne 0,1,99;
          end;

          *** checking if HyprPlas = 0,1 or 99 when NB_Cat ne missing;
          if  (&HyprPlas ^= 0  &  &HyprPlas ^= 1  &  &HyprPlas ^= 99) then  rrHypr = .;


          if (NB_Cat = .  |
              AM_Cat = .  |
              AF_Cat = .  |
              NR_Cat = .  |
              rrHypr = .  ) then  &Error_Ind = 1;




          if      (&Error_Ind = 1) then do;                  *** errornous input record;
             &RelRsk    = .;
             &AbsRsk    = .;
             &se_AbsRsk = .;
             &Lo_95ci   = .;
             &Hi_95ci   = .;

             Pattrn_ID  = .;

             if (irows <= 100) then

                put (              &IDD)       7.0
                    (               &T1)       6.1
                    (               &T2)       6.1
                    (           &NBiops)       6.0
                    (           &AgeMen)       5.0
                    (           &AgeFst)       5.0
                    (           &NumRel)       5.0
                    (         &HyprPlas)       6.0
                    (            rrHypr)       6.2
                    (           &RelRsk)       6.0
                    (           &AbsRsk)       8.0
                    (        &se_AbsRsk)       9.0
                    (          &Lo_95ci)       7.0
                    (          &Hi_95ci)       7.0
                    (             &Race)       3.0
                    (charRace[RaceIndx])  $char3.  ;

             append var {&NBiops  &AgeMen     &AgeFst   &NumRel  &HyprPlas  &T1  &T2   &IDD
                         &RelRsk  &AbsRsk  &se_AbsRsk  &Lo_95ci  &Hi_95ci   &Error_Ind &Race};
          end;
          else if (&Error_Ind = 0) then do;                  *** error free input record;

             Pattrn_ID = NB_Cat * 24 +
                         AM_Cat *  8 +
                         AF_Cat *  2 +
                         NR_Cat *  1 + 1;

             /* test that the mapping Pattrn_ID points to correct row in the matrix ARrrstar_CovARrrstar
                given that input data matrix is in the correct order

             if (Pattrn_ID ^= IIDD) then do;
                file print;
                put  "Pattrn_ID  "  Pattrn_ID 7.0  "  ne   IDD  "  IIDD  7.0;
             end;
             */


             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;

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

                if      (iloop = 1) then
                   RR_1_AR_Hypr= One_AR` # RRofXStar[Pattrn_ID, 1:2] # rrHypr;

                else if (iloop = 2) then
                   RR_1_AR_Hypr=                                     1*j(1,2);

                else if (iloop = 3) then do;
                   &T2         = 90;
                   RR_1_AR_Hypr= One_AR` # RRofXStar[Pattrn_ID, 1:2] # rrHypr;
                end;

                else if (iloop = 4) then do;
                   &T2         = 90;
                   RR_1_AR_Hypr=                                     1*j(1,2);
                end;



                &RelRsk     = RRofXStar[Pattrn_ID, 1] # rrHypr;

                *** selecting correct h1 and h2 based on race;
                h1 = h1_prnt[1:70, &race];
                h2 = h2_prnt[1:70, &race];

                *** involking defined module "Eq2_3";
                &AbsRsk = Eq2_3(RR_1_AR_Hypr);

                call nlpfdd(crit, Gradient, hessian, "Eq2_3", RR_1_AR_Hypr);

                *** covariance of (1-AR)*RRstar;
                Cov_AR_RR      =(CovARrrstar[Pattrn_ID,1] ||
                                 CovARrrstar[Pattrn_ID,3])//
                                (CovARrrstar[Pattrn_ID,3] ||
                                 CovARrrstar[Pattrn_ID,2]);

                Varnc_PI_A     = Gradient*Cov_AR_RR*(Gradient`);          *** variance of PI;
                &se_AbsRsk     = sqrt(Varnc_PI_A);

                *** find logit transform and the taylor variance, 95 percent CI of the logit;

                YYY        = log(&AbsRsk/(1-&AbsRsk));
                Var_YYY    =( 1/(&AbsRsk*(1-&AbsRsk))) * Varnc_PI_A *
                            ( 1/(&AbsRsk*(1-&AbsRsk)));
                ci_YYY     =(YYY - 1.96*sqrt(VAR_YYY)) || (YYY + 1.96*sqrt(VAR_YYY));

                *** 95 percent CI of the inverse logit;

                &Lo_95ci = (exp(ci_YYY[1])/(1+exp(ci_YYY[1])));
                &Hi_95ci = (exp(ci_YYY[2])/(1+exp(ci_YYY[2])));

                &AbsRsk    = 100 * &AbsRsk ;
                &se_AbsRsk = 100 * &se_AbsRsk;
                &Lo_95ci   = 100 * &Lo_95ci;
                &Hi_95ci   = 100 * &Hi_95ci;

                append var {&NBiops  &AgeMen     &AgeFst   &NumRel  &HyprPlas  &T1  &T2   &IDD
                            &RelRsk  &AbsRsk  &se_AbsRsk  &Lo_95ci  &Hi_95ci   &Error_Ind &Race};

                iloop = iloop + 1;
             end;
          end;

          irows = irows + 1;
       end;
   quit;


   data  &Out_File;
   set   &Out_File;

         label  &Error_Ind = "If mean not 0, implies Bad Records on input file"
                &AbsRsk    = "Absolute risk of BrCa (%)";
   run;


   proc  means  data=&Out_File  mean n nmiss  maxdec=4;
   var  &Error_Ind
        &AbsRsk
        &RelRsk;


   title3  "Quick check for errornous records on input file";
   title4  " ";
   title5  "IF MEAN OF  &Error_Ind   EQUALS  0   ==>   Input file is  ERROR  FREE";
   title6  "Otherwise bad records in input file";
   title8  "(# of records with errors is the # listed under the NMiss column in the"
           " 'AbsRsk' line)";


%mend    APA_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;
run;
