******************************************************************************************
*The following is JCL if you are using an IBM-type mainframe:
*
*
*//JOBCARD
*//E2425T1P EXEC SAS94,REGION=8M,
*// OPTIONS='ERRORS=0,NOCENTER,NEWS'
*//WORK  DD SPACE=(CYL,(1000,2))
*//WORK1   DD SPACE=(CYL,(2000,2))
*//LIBRARY DD DISP=SHR,DSN=XXXX.XXXXXXX  /* user-defined location of formats */
*//IN0 DD DISP=SHR,DSN=XXXX.XXXXXX       /*user-defined location of macros  */
*//IN1 DD DISP=SHR,DSN=XXXX.PERSON       /*the location of person-level file  */
*//IN2 DD DISP=SHR,DSN=XXXX.DIAG         /*the location of the diagnosis file */  
*//INCOEF DD DISP=SHR,DSN=XXXX.HCCCOEFN  /*the location of the file containing all coefficients */
*//OUT DD DISP=(NEW,CATLG,KEEP),
*//    DSN=XXX.E2425T1P.PERSON,          /*the output file containing person-level scores */ 
*//    SPACE=(TRK,(20,10),RLSE)
*//SYSIN  DD *
*
*
******************************************************************************************
*  If you are using PC-SAS, you must specify the location of the files 
*  on your PC in a libname/filename statement.
*
*LIBNAME LIBRARY "location of formats";
*FILENAME IN0 "location of macros";  
*LIBNAME IN1 "location of person-level file";
*LIBNAME IN2 "location of diagnosis file";
*LIBNAME INCOEF "location of the coefficients file";
*LIBNAME OUT "location for the output file"; 
*
 /*********************************************************************
 * E2425T1P program creates eighty-six HCC variables Version 24
 * (&HCCV24_list86) and twenty-nine score variables for each person who  
 * is present in a person file (supplied by a user).
 * If a person has at least one diagnosis in DIAG file (supplied by a
 * user) then HCC variables are created, otherwise HCCs are set to 0.
 * Score variables are created using coefficients from 8 final models:
 * Dialysis Continuing Enrollee, Dialysis New Enrollee, 
 * Functioning Graft Community NonDual and Partial Benefit Dual Aged,
 * Functioning Graft Community NonDual and Partial Benefit Dual NonAged,
 * Functioning Graft Community Full Benefit Dual Aged,
 * Functioning Graft Community Full Benefit Dual NonAged,
 * Functioning Graft Institutional, Functioning Graft New Enrollee.
 *
 * Assumptions about input files:
 *   - both files are sorted by person ID
 *   - person level file has the following variables:
 *     :&IDVAR  - person ID variable (it is a macro parameter, MBI for 
 *                Medicare data)
 *     :DOB     - date of birth
 *     :SEX     - gender
 *     :OREC    - original reason for entitlement
 *     :PBDual  - partial dual benefit status
 *     :FBDual  - full dual benefit status
 *     :LTI     - LTI status
 *                
 *   - diagnosis level file has the following variables:
 *     :&IDVAR    - person ID variable (it is a macro parameter, MBI 
 *                  for Medicare data)
 *     :DIAG      - diagnosis
 *
 * The program supplies parameters to a main macro %E2425T1M that calls
 * other external macros:
 *      %AGESEXV2 - create age/sex, originally disabled, disabled vars
 *      %V24I0ED3 - perform edits to ICD10 diagnosis
 *      %V24H86L1 - assign labels to HCCs
 *      %V24H86H1 - set HCC=0 according to hierarchies
 *      %SCOREVAR - calculate a score variable
 *
 * Program steps:
 *         step1: include external macros
 *         step2: define internal macro variables
 *         step3: merge person and diagnosis files outputting one
 *                record per person for each input person level record
 *         step3.1: declaration section
 *         step3.2: bring regression coefficients
 *         step3.3: merge person and diagnosis file
 *         step3.4: for the first record for a person set CC to 0
 *                  and calculate age
 *         step3.5: if there are any diagnoses for a person
 *                  then do the following:
 *                   - perform ICD10 edits using V24I0ED3 macro 
 *                   - create CC using provided format 
 *                   - create additional CC using additional formats
 *         step3.6: for the last record for a person do the
 *                  following:
 *                   - create demographic variables needed
 *                     for regressions (macro AGESEXV2)
 *                   - create HCC using hierarchies (macro V24H86H1)
 *                   - create HCC interaction variables
 *                   - create HCC and Non-Aged interaction variables
 *                   - set to 0 HCCs and interaction variables if there
 *                     are no diagnoses for a person
 *                   - create 29 score variables:
 *	 dialysis:  
 *   SCORE_DIAL                     - dialysis score                  
 *   SCORE_DIAL_NE                  - dialysis new enrollees score
 *  kidney transplant:                                           
 *   SCORE_TRANS_KIDNEY_ONLY_1M     - first month score
 *   SCORE_TRANS_KIDNEY_ONLY_2M     - second month score
 *   SCORE_TRANS_KIDNEY_ONLY_3M     - third month score               
 *  functioning graft community non-dual/partial benefit dual:   
 *   SCORE_G_COMM_ND_PBD_GE65_DUR4_9   - 4-9 months duration, aged
 *   SCORE_G_COMM_ND_PBD_GE65_DUR10PL  - 10+ months duration, aged
 *   SCORE_G_COMM_ND_PBD_LT65_DUR4_9   - 4-9 months duration, non-aged
 *   SCORE_G_COMM_ND_PBD_LT65_DUR10PL  - 10+ months duration, non-aged
 *  functioning graft community full benefit dual:   
 *   SCORE_G_COMM_FB_GE65_DUR4_9   - 4-9 months duration, aged
 *   SCORE_G_COMM_FB_GE65_DUR10PL  - 10+ months duration, aged
 *   SCORE_G_COMM_FB_LT65_DUR4_9   - 4-9 months duration, non-aged
 *   SCORE_G_COMM_FB_LT65_DUR10PL  - 10+ months duration, non-aged
 *  functioning graft institutional non-dual/partial benefit dual:   
 *   SCORE_G_INST_ND_PBD_GE65_DUR4_9   - 4-9 months duration, aged
 *   SCORE_G_INST_ND_PBD_GE65_DUR10PL  - 10+ months duration, aged
 *   SCORE_G_INST_ND_PBD_LT65_DUR4_9   - 4-9 months duration, non-aged
 *   SCORE_G_INST_ND_PBD_LT65_DUR10PL  - 10+ months duration, non-aged
 *  functioning graft institutional full benefit dual:   
 *   SCORE_G_INST_FB_GE65_DUR4_9   - 4-9 months duration, aged
 *   SCORE_G_INST_FB_GE65_DUR10PL  - 10+ months duration, aged
 *   SCORE_G_INST_FB_LT65_DUR4_9   - 4-9 months duration, non-aged
 *   SCORE_G_INST_FB_LT65_DUR10PL  - 10+ months duration, non-aged
 *  functioning graft new enrollee non-dual/partial benefit dual:   
 *   SCORE_G_NE_ND_PBD_GE65_DUR4_9     - 4-9 months duration, aged
 *   SCORE_G_NE_ND_PBD_GE65_DUR10PL    - 10+ months duration, aged
 *   SCORE_G_NE_ND_PBD_LT65_DUR4_9     - 4-9 months duration, non-aged
 *   SCORE_G_NE_ND_PBD_LT65_DUR10PL    - 10+ months duration, non-aged
 *  functioning graft new enrollee full benefit dual:   
 *   SCORE_G_NE_FB_GE65_DUR4_9     - 4-9 months duration, aged
 *   SCORE_G_NE_FB_GE65_DUR10PL    - 10+ months duration, aged
 *   SCORE_G_NE_FB_LT65_DUR4_9     - 4-9 months duration, non-aged
 *   SCORE_G_NE_FB_LT65_DUR10PL    - 10+ months duration, non-aged
 *
 *         step4: data checks and proc contents
 *
 *   USER CUSTOMIZATION:
 * User must supply 2 files with the variables described above and
 * set the following parameters:
 *      INP       - SAS input person dataset
 *      IND       - SAS input diagnosis dataset
 *      OUTDATA   - SAS output dataset
 *      IDVAR     - name of person ID variable (MBI for Medicare data)
 *      KEEPVAR   - variables to keep in the output dataset
 *      SEDITS    - a switch that controls whether to perform MCE edits  
 *                  on ICD10: 1-YES, 0-NO
 *      DATE_ASOF - reference date to calculate age. Set to February 1  
 *                  of the payment year for consistency with CMS 
 *      DF_DG     - normalization factor set by CMS, used to multiply 
 *                  dialysis and transplant scores (currently set to 1 
 *                  by default)
 *      DF_POSTG  - normalization factor set by CMS, used to multiply 
 *                  post-graft scores (currently set to 1 by default)
 *********************************************************************/;

 %LET INPUTVARS=%STR(SEX DOB OREC FBDual PBDual LTI);

 %*some of demographic variables created by the software; 
 %LET DEMVARS  =%STR(AGEF DISABL ORIGDS
                     F0_34  F35_44 F45_54 F55_59 F60_64 F65_69
                     F70_74 F75_79 F80_84 F85_89 F90_94 F95_GT
                     M0_34  M35_44 M45_54 M55_59 M60_64 M65_69
                     M70_74 M75_79 M80_84 M85_89 M90_94 M95_GT

                     NEF0_34  NEF35_44 NEF45_54 NEF55_59 NEF60_64
                     NEF65    NEF66    NEF67    NEF68    NEF69
                     NEF70_74 NEF75_79 NEF80_84 NEF85_89 NEF90_94
                     NEF95_GT NEF85_GT NEF65_69
                     NEM0_34  NEM35_44 NEM45_54 NEM55_59 NEM60_64
                     NEM65    NEM66    NEM67    NEM68    NEM69
                     NEM70_74 NEM75_79 NEM80_84 NEM85_89 NEM90_94
                     NEM95_GT NEM85_GT NEM65_69);

 %*list of HCCs included in models;
 %LET HCCV24_list86 = %STR(      
      HCC1    HCC2    HCC6    HCC8    HCC9    HCC10   HCC11   HCC12
      HCC17   HCC18   HCC19   HCC21   HCC22   HCC23   HCC27   HCC28
      HCC29   HCC33   HCC34   HCC35   HCC39   HCC40   HCC46   HCC47
      HCC48   HCC51   HCC52   HCC54   HCC55   HCC56   HCC57   HCC58   
      HCC59   HCC60   HCC70   HCC71   HCC72   HCC73   HCC74   HCC75   
      HCC76   HCC77   HCC78   HCC79   HCC80   HCC82   HCC83   HCC84   
      HCC85   HCC86   HCC87   HCC88   HCC96   HCC99   HCC100  HCC103  
      HCC104  HCC106  HCC107  HCC108  HCC110  HCC111  HCC112  HCC114  
      HCC115  HCC122  HCC124  HCC134  HCC135  HCC136  HCC137  HCC138  
      HCC157  HCC158  HCC159  HCC161  HCC162  HCC166  HCC167  HCC169  
      HCC170  HCC173  HCC176  HCC186  HCC188  HCC189
      );

 %*list of CCs that correspond to model HCCs;
 %LET CCV24_list86 = %STR(      
      CC1     CC2     CC6     CC8     CC9     CC10    CC11    CC12
      CC17    CC18    CC19    CC21    CC22    CC23    CC27    CC28
      CC29    CC33    CC34    CC35    CC39    CC40    CC46    CC47
      CC48    CC51    CC52    CC54    CC55    CC56    CC57    CC58    
      CC59    CC60    CC70    CC71    CC72    CC73    CC74    CC75    
      CC76    CC77    CC78    CC79    CC80    CC82    CC83    CC84    
      CC85    CC86    CC87    CC88    CC96    CC99    CC100   CC103   
      CC104   CC106   CC107   CC108   CC110   CC111   CC112   CC114   
      CC115   CC122   CC124   CC134   CC135   CC136   CC137   CC138   
      CC157   CC158   CC159   CC161   CC162   CC166   CC167   CC169   
      CC170   CC173   CC176   CC186   CC188   CC189
      );

 %LET SCOREVARS=%STR(SCORE_DIAL
                     SCORE_DIAL_NE
                     SCORE_TRANS_KIDNEY_ONLY_1M
                     SCORE_TRANS_KIDNEY_ONLY_2M
                     SCORE_TRANS_KIDNEY_ONLY_3M
                     SCORE_G_COMM_ND_PBD_GE65_DUR4_9
                     SCORE_G_COMM_ND_PBD_GE65_DUR10PL
                     SCORE_G_COMM_ND_PBD_LT65_DUR4_9
                     SCORE_G_COMM_ND_PBD_LT65_DUR10PL
                     SCORE_G_COMM_FBD_GE65_DUR4_9
                     SCORE_G_COMM_FBD_GE65_DUR10PL
                     SCORE_G_COMM_FBD_LT65_DUR4_9
                     SCORE_G_COMM_FBD_LT65_DUR10PL
                     SCORE_G_INST_ND_PBD_GE65_DUR4_9
                     SCORE_G_INST_ND_PBD_GE65_DUR10PL
                     SCORE_G_INST_ND_PBD_LT65_DUR4_9
                     SCORE_G_INST_ND_PBD_LT65_DUR10PL
                     SCORE_G_INST_FBD_GE65_DUR4_9
                     SCORE_G_INST_FBD_GE65_DUR10PL
                     SCORE_G_INST_FBD_LT65_DUR4_9
                     SCORE_G_INST_FBD_LT65_DUR10PL
                     SCORE_G_NE_ND_PBD_GE65_DUR4_9
                     SCORE_G_NE_ND_PBD_GE65_DUR10PL
                     SCORE_G_NE_ND_PBD_LT65_DUR4_9
                     SCORE_G_NE_ND_PBD_LT65_DUR10PL
                     SCORE_G_NE_FBD_GE65_DUR4_9
                     SCORE_G_NE_FBD_GE65_DUR10PL
                     SCORE_G_NE_FBD_LT65_DUR4_9
                     SCORE_G_NE_FBD_LT65_DUR10PL
                     DF_DG
                     DF_POSTG
                     ActAdj_DUR4_9 
                     ActAdj_DUR10PL
                     );

  %INCLUDE IN0(E2425T1M)/SOURCE2; *include main macro ;

  *MACRO call;
  %E2425T1M (INP       =IN1.PERSON,
             IND       =IN2.DIAG,
             OUTDATA   =OUT.PERSON,
             IDVAR     =MBI,
             KEEPVAR   =MBI &INPUTVARS &SCOREVARS &DEMVARS 
                        &HCCV24_list86 &CCV24_list86,
             SEDITS    =1,
             DATE_ASOF ="1FEB2025"D, 
             DF_DG     =1,
             DF_POSTG  =1);
