/*Published: 12/1/2020*/
/*                                                                     */
/**********************   COMMENTS   ***********************************/
/*                                                                     */
/* Please Note: If you are using PC SAS to read in these files you     */
/* will have to un-zip the files first and use the un-zipped filename  */
/* statement, rather than using the zipped files and statement.        */
/*                                                                     */
/* This version is for the Part D Formulary files for 2010-2018.       */
/* Formulary variables for 2007-2009 are included in the PDE Event     */
/* files for those years.                                              */
/*                                                                     */
/***********************************************************************/

*  This format is for the Formulary file for 2010-2018;

*filename formin '/directory/formulary_2018.dat';                      /*reading in an un-zipped file*/
*filename formin pipe 'gunzip -c /directory/formulary_2018.dat.gz';     /*reading in a zipped file*/
filename formin pipe 'gunzip -c /directory/formulary_*.dat.gz';     /*using wildcard to match multiple files */

options nocenter validvarname=upcase;

data formulary;
  infile formin lrecl=136 missover pad;
  input @001   FORMULARY_ID                     $char8.
        @009   FRMLRY_RX_ID                     $char8.
        @017   TIER_ID                          $char2.
        @019   STEP                             $char2.
        @021   QUANTITY_LIMIT_YN                $char2.
        @023   PRIOR_AUTHORIZATION_YN           $char2.
        @025   BN                               $char30.
        @055   GNN                              $char30.
        @085   STR                              $char10.
        @095   GCDF                             $char2.
        @097   GCDF_DESC                        $char40.
     ;

  label  FORMULARY_ID                     = "Unique ID Assigned to Each Newly Created Formulary"
         FRMLRY_RX_ID                     = "CCW Identifier for a Drug Product Found in a Part D Prescription Drug Plan Formulary"
         TIER_ID                          = "Formulary Tier Number"
         STEP                             = "Step Number within a Step Therapy Group"
         QUANTITY_LIMIT_YN                = "Quantity Limits? (1=Yes)"
         PRIOR_AUTHORIZATION_YN           = "Prior Authorization? (1=Yes)"
         BN                               = "FDB Brand Name"
         GNN                              = "FDB USAN Generic Name - Short Version"
         STR                              = "FDB Drug Strength Description"
         GCDF                             = "FDB Dosage Form Code"
         GCDF_DESC                        = "FDB Dosage Form Code Description"
     ;
run;

proc contents data=formulary position;
run;
*  This format is for the Excl Drug file for 2011;

*filename exclin1 '/directory/excl_drugs_2011.dat';                      /*reading in an un-zipped file*/
*filename exclin1 pipe 'gunzip -c /directory/excl_drugs_2011.dat.gz';     /*reading in a zipped file*/
*filename exclin1 pipe 'gunzip -c /directory/excl_drugs_*.dat.gz';     /* Only 2011 uses this format */
*****CHANGED INPUT STATEMENT****** ONLY CHANGE TO INPUT STATEMENT ;
filename exclin1 pipe 'gunzip -c /prj/mdcost/mkmedic/link20/PartD.Char/Formulary/excl_drugs_2011.dat.gz';        /*reading in a zipped file*/

options nocenter validvarname=upcase;

data excl_drug1;
  infile exclin1 lrecl=138 missover pad;
  input @001   CONTRACT_ID                      $char5.
        @006   PLAN_ID                          $char3.
        @009   FORMULARY_ID                     $char8.
        @017   FRMLRY_RX_ID                     $char8.
        @025   TIER_ID                          $char2.
        @027   BN                               $char30.
        @057   GNN                              $char30.
        @087   STR                              $char10.
        @097   GCDF                             $char2.
        @099   GCDF_DESC                        $char40.
     ;

  label  CONTRACT_ID                      = "Part D Contract ID"
         PLAN_ID                          = "Part D Plan ID"
         FORMULARY_ID                     = "Unique ID Assigned to Each Newly Created Formulary"
         FRMLRY_RX_ID                     = "CCW Identifier for a Drug Product Found in a Part D Prescription Drug Plan Formulary"
         TIER_ID                          = "Cost share tier level associated with the drug"
         BN                               = "FDB Brand Name"
         GNN                              = "FDB USAN Generic Name - Short Version"
         STR                              = "FDB Drug Strength Description"
         GCDF                             = "FDB Dosage Form Code"
         GCDF_DESC                        = "FDB Dosage Form Code Description"
     ;
run;

proc contents data=excl_drug1 position;
run;
*  This format is for the Excl Drug file for 2012-2018;

*filename exclin2 '/directory/excl_drugs_2018.dat';                      /*reading in an un-zipped file*/
*filename exclin2 pipe 'gunzip -c /directory/excl_drugs_2018.dat.gz';     /*reading in a zipped file*/
*filename exclin2 pipe 'gunzip -c /directory/excl_drugs_*.dat.gz';     /*using wildcard to match multiple files -Not to be used with 2011 file */
*****CHANGED INPUT STATEMENT****** ONLY CHANGE TO INPUT STATEMENT ;
filename exclin2 pipe 'gunzip -c /prj/mdcost/mkmedic/link20/PartD.Char/Formulary/excl_drugs_2018.dat.gz';        /*reading in a zipped file*/

options nocenter validvarname=upcase;

data excl_drug2;
  infile exclin2 lrecl=136 missover pad;
  input @001   FORMULARY_ID                     $char8.
        @009   FRMLRY_RX_ID                     $char8.
        @017   TIER_ID                          $char2.
        @019   STEP_THERAPY_YN                  $char2.
        @021   QUANTITY_LIMIT_YN                $char2.
        @023   PRIOR_AUTHORIZATION_YN           $char2.
        @025   BN                               $char30.
        @055   GNN                              $char30.
        @085   STR                              $char10.
        @095   GCDF                             $char2.
        @097   GCDF_DESC                        $char40.;
     ;

  label  FORMULARY_ID                     = "Unique ID Assigned to Each Newly Created Formulary"
         FRMLRY_RX_ID                     = "CCW Identifier for a Drug Product Found in a Part D Prescription Drug Plan Formulary"
         TIER_ID                          = "Cost Share Tier Level Associated with the Drug"
         STEP_THERAPY_YN                  = "Excluded Drug Step Therapy? (1=Yes)"
         QUANTITY_LIMIT_YN                = "Excluded Drug Quantity Limit? (1=Yes)"
         PRIOR_AUTHORIZATION_YN           = "Excluded Drug Prior Authorization? (1=Yes)"
         BN                               = "FDB Brand Name"
         GNN                              = "FDB USAN Generic Name - Short Version"
         STR                              = "FDB Drug Strength Description"
         GCDF                             = "FDB Dosage Form Code"
         GCDF_DESC                        = "FDB Dosage Form Code Description"
     ;
run;

proc contents data=excl_drug2 position;
run;
*  This format is for the Drug Char file for 2016-2018;

*filename drugin '/directory/drug_char_2018.dat';                      /*reading in an un-zipped file*/
*filename drugin pipe 'gunzip -c /directory/drug_char_2018.dat.gz';     /*reading in a zipped file*/
*filename drugin pipe 'gunzip -c /directory/drug_char_*.dat.gz';     /*using wildcard to match multiple files */
*****CHANGED INPUT STATEMENT****** ONLY CHANGE TO INPUT STATEMENT ;
filename drugin pipe 'gunzip -c /prj/mdcost/mkmedic/link20/PartD.Char/Formulary/drug_char_2018.dat.gz';        /*reading in a zipped file*/

options nocenter validvarname=upcase;

data drug_char;
  infile drugin lrecl=123 missover pad;
  input @001   NDC                              $char11.
        @012   BN                               $char30.
        @042   GNN                              $char30.
        @072   STR                              $char10.
        @082   GCDF                             $char2.
        @084   GCDF_DESC                        $char40.
     ;

  label  NDC                              = "11-digit NDC"
         BN                               = "Brand Name"
         GNN                              = "USAN Generic Name - Short Version"
         STR                              = "Drug Strength Description"
         GCDF                             = "Dosage Form Code (2 character)"
         GCDF_DESC                        = "Dosage Form Code Description"
     ;
run;

proc contents data=drug_char position;
run;
*  This format is for the OTC Drug file for 2011-2018;

filename otcin '/directory/otc_drugs_2018.dat';                      /*reading in an un-zipped file*/
*filename otcin pipe 'gunzip -c /directory/otc_drugs_2018.dat.gz';     /*reading in a zipped file*/
*filename otcin pipe 'gunzip -c /directory/otc_drugs_*.dat.gz';     /*using wildcard to match multiple files */
*****CHANGED INPUT STATEMENT****** ONLY CHANGE TO INPUT STATEMENT ;
filename otcin pipe 'gunzip -c /prj/mdcost/mkmedic/link20/PartD.Char/Formulary/otc_drugs_2018.dat.gz';        /*reading in a zipped file*/

options nocenter validvarname=upcase;

data otc_drug;
  infile otcin lrecl=128 missover pad;
  input @001   FORMULARY_ID                     $char8.
        @009   FRMLRY_RX_ID                     $char8.
        @017   BN                               $char30.
        @047   GNN                              $char30.
        @077   STR                              $char10.
        @087   GCDF                             $char2.
        @089   GCDF_DESC                        $char40.
     ;

  label  FORMULARY_ID                     = "Unique ID Assigned to Each Newly Created Formulary"
         FRMLRY_RX_ID                     = "CCW Identifier for a Drug Product Found in a Part D Prescription Drug Plan Formulary"
         BN                               = "FDB Brand Name"
         GNN                              = "FDB USAN Generic Name - Short Version"
         STR                              = "FDB Drug Strength Description"
         GCDF                             = "FDB Dosage Form Code"
         GCDF_DESC                        = "FDB Dosage Form Code Description"
     ;
run;

proc contents data=otc_drug position;
run;


