Real World Health Care Data Analysis. Uwe Siebert
* &&_nvar&contloop2;
LABEL int_n&contloop._n&contloop2 = “&&_nlab&contloop *
&&_nlab&contloop2”;
%LET interactionscont = &interactionscont int_n&contloop._n&contloop2;
%END;
%END;
RUN;
PROC FORMAT;
VALUE $cont
%DO iloop = 1 %TO &_nnvar;
“n&iloop” = “&&_nvar&iloop”
%END;
;
RUN;
%* Get the number of interactions between continuous covariates as well
as their separate names *;
DATA _NULL_;
vars = “&interactionscont”;
i = 1;
var = SCAN(vars, i);
DO WHILE (var ^= ‘’);
CALL SYMPUT(‘_nint’||COMPRESS(PUT(i, BEST.)), TRIM(LEFT(var)));
i + 1;
var = SCAN(vars, i);
END;
CALL SYMPUT(‘_nnint’, COMPRESS(PUT(i - 1, BEST.))); RUN;
%* Calculate Standardized Bias for continuous covariates and
interactions between continuous variables;
PROC SUMMARY DATA = _indata_int (WHERE = (_strata_ ^= .)) NWAY;
CLASS _strata_ _cohort;
VAR &contvars &interactionscont;
OUTPUT OUT = _mean MEAN = STD = /AUTONAME; RUN;
PROC TRANSPOSE DATA=_mean (DROP=_type_ _freq_) OUT=_mean_t PREFIX=trt_;
BY _strata_;
ID _cohort; RUN;
PROC SORT DATA = _mean_t;
BY _strata_ _name_; RUN;
DATA _mean;
LENGTH _label_ $200;
MERGE _mean_t;
BY _strata_ _name_;
_stat = SCAN(_name_, -1, ‘_’);
IF UPCASE(_stat) = ‘MEAN’ THEN _statn = 1;
ELSE _statn = 3;
_name_ = REVERSE(SUBSTR(REVERSE(_name_), INDEX(REVERSE(_name_), ‘_’)
+ 1)); RUN;
PROC SORT DATA = _mean;
BY _strata_ _name_ _statn; RUN;
DATA _stddiff;
SET _mean;
BY _strata_ _name_ _statn;
RETAIN stddiff;
IF UPCASE(_stat) = ‘MEAN’ THEN
DO;
stddiff = trt_1 - trt_0;
END;
ELSE IF UPCASE(_stat) = ‘STDDEV’ THEN
DO;
stddiff = stddiff / trt_1;
END;
IF LAST._name_; RUN;
DATA _stddiff;
LENGTH variable1 variable2 $32;
SET _stddiff;
IF UPCASE(_name_) =: ‘INT_’ THEN
DO;
variable1 = UPCASE(PUT(SCAN(_name_, 2, ‘_’), $cont.));
variable2 = UPCASE(PUT(SCAN(_name_, 3, ‘_’), $cont.));
END;
ELSE variable1 = _name_;
IF variable1 ^= ‘’;
KEEP variable1 variable2 stddiff _strata_; RUN;
%* Now for every (binary) categorical covariate we calculate per strata the standardized bias for the covariate and for all interactions between the covariate and continuous covariates and all levels of all other categorical covariates;
DATA _mean;
STOP; RUN;
DATA _meancont;
STOP; RUN;
DATA _meanclass;
STOP; RUN;
%DO iloop = 1 %TO &_ncvar;
PROC SUMMARY DATA = _indata_int (WHERE = (_strata_ ^= .)) NWAY;
CLASS _strata_ _cohort;
VAR &&_cvar&iloop;
OUTPUT OUT = _mean0 MEAN = mean /AUTONAME; RUN;
DATA _mean;
LENGTH variable1 $32;
SET _mean _mean0 (IN = in);
IF in THEN
variable1 = UPCASE(“&&_cvar&iloop”); RUN;
PROC SUMMARY DATA = _indata_int (WHERE = (_strata_ ^= .)) NWAY;
WHERE &&_cvar&iloop;
CLASS _strata_ _cohort;
VAR &contvars;
OUTPUT OUT = _mean1 MEAN = STD = /AUTONAME; RUN;
DATA _meancont;
LENGTH variable1 $32;
SET _meancont _mean1 (IN = in);
IF in THEN
variable1 = UPCASE(“&&_cvar&iloop”); RUN;
PROC SUMMARY DATA = _indata_int (WHERE = (_strata_ ^= .)) NWAY;
WHERE &&_cvar&iloop;
CLASS _strata_ _cohort;
VAR &classvars_bin;
OUTPUT OUT = _mean2 MEAN =; RUN;
DATA _meanclass;
LENGTH variable1 $32;
SET _meanclass _mean2 (IN = in);
IF in THEN
variable1 = UPCASE(“&&_cvar&iloop”); RUN;
%END;
PROC SORT DATA = _meancont;
BY variable1 _strata_; RUN;
PROC TRANSPOSE DATA = _meancont (DROP = _type_ _freq_) OUT =
_meancont_t PREFIX = trt_;
BY variable1 _strata_;
ID _cohort; RUN;
PROC SORT DATA = _meancont_t;
BY variable1 _strata_ _name_; RUN;
DATA _meancont;
SET _meancont_t;
_stat = SCAN(_name_, -1, ‘_’);
IF UPCASE(_stat) = ‘MEAN’ THEN _statn = 1;
ELSE _statn = 3;
_name_ = REVERSE(SUBSTR(REVERSE(_name_), INDEX(REVERSE(_name_), ‘_’) + 1));
RUN;
PROC SORT DATA = _meancont;
BY variable1 _strata_ _name_ _statn;
RUN;
DATA stddiff1_ (RENAME = (_name_