Real World Health Care Data Analysis. Uwe Siebert

Real World Health Care Data Analysis - Uwe Siebert


Скачать книгу
if this variable is part of an interaction term in the logistic model. Program 4.8 provides a macro to calculate the standardized bias of the covariates and their interaction terms included in the model. This macro will be called in program 4.8.

      Program 4.7: Macro to Create a Binary Indicator for Multi-categorical Variables

      ***************************************************************************

      Macro: _ps_indic

      ****************************************************************************;

      %MACRO _ps_indic (in =, out =, full = NO);

      PROC CONTENTS DATA = &in (KEEP = &classvars) NOPRINT OUT = _cont; RUN;

      DATA _NULL_;

      SET _cont (KEEP = name label type format) END = last;

      CALL SYMPUT(COMPRESS(‘_cvar’||PUT(_N_, BEST.)), TRIM(LEFT(name)));

      IF label ^= ‘’ THEN

      CALL SYMPUT(COMPRESS(‘_clab’||PUT(_N_, BEST.)), TRIM(LEFT(label)));

      ELSE CALL SYMPUT(COMPRESS(‘_clab’||PUT(_N_, BEST.)),

      TRIM(LEFT(name)));

      CALL SYMPUT(COMPRESS(‘_ctype’||PUT(_N_, BEST.)), type);

      CALL SYMPUT(COMPRESS(‘_cfmt’||PUT(_N_, BEST.)), format);

      IF last THEN

      CALL SYMPUT(‘_ncvar’, COMPRESS(PUT(_n_, BEST.))); RUN;

      %* Get the number of categorical covariates (_nnvar) and name and label

      of separate categorical covariatest (_nvar# and nlab#).*;

      %LET classvars_bin =;

      DATA &out;

      SET ∈ RUN;

      %DO iloop = 1 %TO &_ncvar;

      %* Create indicator (0/1) variables for all categorical

      covariates and put their names in macro var CLASSVARS_BIN *;

      PROC SQL;

      CREATE TABLE _cvar&iloop AS SELECT DISTINCT

      TRIM(LEFT(&&_cvar&iloop)) AS &&_cvar&iloop FROM &in WHERE NOT

      MISSING(&&_cvar&iloop);

      QUIT;

      %IF %SUBSTR(%QUPCASE(&full), 1, 1) = Y %THEN

      %LET _n&iloop = &sqlobs;

      %ELSE %LET _n&iloop = %EVAL(&sqlobs - 1);

      DATA _NULL_;

      SET _cvar&iloop;

      %IF &&_ctype&iloop = 2 %THEN

       %DO;

      %IF %BQUOTE(&&_cfmt&iloop) ^= %THEN

      CALL SYMPUT (‘_vlab_’||COMPRESS(PUT(_N_, BEST.)),

      “&&_clab&iloop “||TRIM(LEFT(PUT(&&_cvar&iloop,

       &&_cfmt&iloop...))));

      %ELSE CALL SYMPUT (‘_vlab_’||COMPRESS(PUT(_N_, BEST.)),

       “&&_clab&iloop “||TRIM(LEFT(&&_cvar&iloop)));

       ;

      %END;

      %ELSE

      %DO;

      %IF %BQUOTE(&&_cfmt&iloop) ^= %THEN

      CALL SYMPUT (‘_vlab_’||COMPRESS(PUT(_N_, BEST.)),

      “&&_clab&iloop “||TRIM(LEFT(PUT(&&_cvar&iloop,

       &&_cfmt&iloop...))));

      %ELSE CALL SYMPUT (‘_vlab_’||COMPRESS(PUT(_N_, BEST.)),

       “&&_clab&iloop “||TRIM(LEFT(PUT(&&_cvar&iloop, BEST.))));

      ;

      %END; RUN;

      PROC TRANSPOSE DATA = _cvar&iloop OUT = _cvar&iloop;

      VAR &&_cvar&iloop; RUN;

      DATA &out;

      IF _N_ = 1 THEN SET _cvar&iloop;

      SET &out;

      %DO jloop = 1 %TO &&_n&iloop;

      %LET classvars_bin = &classvars_bin &&_cvar&iloop.._&jloop;

      IF &&_cvar&iloop = col&jloop THEN

      &&_cvar&iloop.._&jloop = 1;

      ELSE IF NOT MISSING(&&_cvar&iloop) THEN

      &&_cvar&iloop.._&jloop = 0;

      %LET _label&iloop._&jloop = &&_vlab_&jloop;

      LABEL &&_cvar&iloop.._&jloop = “&&_vlab_&jloop”;

      DROP col&jloop;

      %END;

      DROP _name_ %IF %SUBSTR(%QUPCASE(&full), 1, 1) ^= Y %THEN

      col%EVAL(&&_n&iloop + 1);;

      RUN;

      %END;

      %MEND _ps_indic;

      Program 4.8: Macro to Calculate the Standardized Bias

      ****************************************************************************

      Macro: _ps_stddiff_apmb

      ****************************************************************************;

      %MACRO _ps_stddiff_apmb (indata = , interactions = YES);

      %_ps_indic(in = &indata, out = _indata_int, full = YES);

      %* Get the number of binary categorical covariates as well as their

      separate names *;

      DATA _NULL_;

      vars = “&classvars_bin”;

      i = 1;

      var = SCAN(vars, i);

      DO WHILE (var ^= ‘’);

      CALL SYMPUT(‘_cvar’||COMPRESS(PUT(i, BEST.)), TRIM(LEFT(var)));

      i + 1;

      var = SCAN(vars, i);

      END;

      CALL SYMPUT(‘_ncvar’, COMPRESS(PUT(i - 1, BEST.))); RUN;

      %* Create interaction variables for continuous covariates *;

      PROC CONTENTS DATA = _indata_int (KEEP = &contvars) NOPRINT OUT = _cont;

      RUN;

      DATA _NULL_;

      SET _cont (KEEP = name label) END = last;

      CALL SYMPUT(COMPRESS(‘_nvar’||PUT(_N_, BEST.)), TRIM(LEFT(name)));

      IF label ^= ‘’ THEN

      CALL SYMPUT(COMPRESS(‘_nlab’||PUT(_N_, BEST.)), TRIM(LEFT(label)));

      ELSE CALL SYMPUT(COMPRESS(‘_nlab’||PUT(_N_, BEST.)), TRIM(LEFT(name)));

      IF last THEN CALL SYMPUT(‘_nnvar’, COMPRESS(PUT(_n_, BEST.)));

      RUN;

      %LET interactionscont =;

      DATA _indata_int;

      SET _indata_int;

      %DO contloop = 1 %TO %EVAL(&_nnvar - 1);

      %DO contloop2 = %EVAL(&contloop + 1) %TO &_nnvar;

      int_n&contloop._n&contloop2


Скачать книгу