/*-------------------------------------------------------------------------------------*\
|  PROGRAM NAME:                                                                        |
|     scdm_data_qa_review-death.sas                                                     |
|                                                                                       |
|---------------------------------------------------------------------------------------|
|  PURPOSE:                                                                             |
|     The purpose of this program is to perform data quality checks on the Death table. |
|---------------------------------------------------------------------------------------|
|  PROGRAM INPUT:                                                                       |
|     see 00.0_scdm_data_qa_review_master_file.sas                                      |
|                                                                                       |
|  PROGRAM OUTPUT:                                                                      |
|     see Workplan PDF                                                                  |
|---------------------------------------------------------------------------------------|
|  CONTACT:                                                                             |
|     Sentinel Coordinating Center                                                      |
|     info@sentinelsystem.org                                                           |
\*-------------------------------------------------------------------------------------*/

*-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-;
*  PLEASE DO NOT EDIT BELOW WITHOUT CONTACTING THE SENTINEL OPERATIONS CENTER           ;
*-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-;

/*-------------------------------------------------------------------------------------*/
/*  START Level 2                                                                      */
/*-------------------------------------------------------------------------------------*/
%let level=2;

/*-------------------------------------------------------------------------------------*/
/*  START Level 2 Flags                                                                */
/*-------------------------------------------------------------------------------------*/
%level2;

/*-------------------------------------------------------------------------------------*/
/*  START Level 3                                                                      */
/*-------------------------------------------------------------------------------------*/
%let level=3;

%let qa_table= ;
%macro get_qa_table ;
  %if &do_partitions and not %eval(&module in &tabid_exc) %then %do ;
    data t_view /view=t_view ;
      set qadata.&&&module.table.: (keep=deathdt) ;
    run;
    %let qa_table = t_view ;
  %end ;
  %else %do;
    %let qa_table = qadata.&&&module.table (keep=deathdt) ;
  %end;
%mend;
%get_qa_table ;
proc sql noprint;
  create table dplocal.&module._temp as 
  select deathdt
       , count(*) as n
  from &qa_table
  group by 1
  ;
quit;
%remove_labels(dplocal,&module._temp)

%date_percentiles (libin=dplocal, dsin=&module._temp, libout=dplocal, dsout=date_dist_&module., vars=deathdt);

proc sql noprint;
  create table msoc.&module._l3_dthdt_ym as
  select put(deathdt,yymmd.) as YearMonth length=7
       , sum(n) as count format=comma15.
  from dplocal.&module._temp
  group by yearmonth
  ;
  drop table dplocal.&module._temp
  ;
quit;

%macro get_qa_table ;
  %if &do_partitions and not %eval(&module in &tabid_exc) %then %do ;
    data t_view /view=t_view ;
      set qadata.&&&module.table.: (keep=dtimpute source confidence) ;
    run;
    %let qa_table = t_view ;
  %end ;
  %else %do;
    %let qa_table = qadata.&&&module.table (keep=dtimpute source confidence) ;
  %end;
%mend;
%get_qa_table ;
proc sql noprint;
  create table msoc.&module._l3_catvars as
  select dtimpute
       , source
       , confidence
       , count(*) as count format=comma15.
  from &qa_table
  group by 1,2,3
  ;
quit;
%remove_labels(msoc,&module._l3_catvars)

*-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-;
*  END scdm_data_qa_review-death.sas                                                    ;
*-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-;