I have a questionnaire coded 1-5 and then labeled as (.) for missing variables. How do I code the data to reflect the following:

If patient has =>80% values not missing than missing values will be coded as the mean value of the questions answered. If patient is missing more than 80% of values than set measure summary to missing for patient, drop record.

condomuse;
set int108;
run;

proc means data=condomuse n nmiss missing;
var cusesability CUSESPurchase CUSESCarry CUSESDiscuss CUSESSuggest CUSESUse CUSESMaintain CUSESEmbarrass CUSESReject CUSESUnsure CUSESConfident CUSESComfort CUSESPersuade CUSESGrace CUSESSucceed;
by Intround sid;
run;

1 Answers

0
Reeza On Best Solutions

Using the following assumptions:

  • each line/record is a unique person
  • all variables are numeric

NMISS(), N(), CMISS() and DIM() are functions that can work with arrays.

This will identify all records with 80% or more missing.

data temp; *temp is output data set name;
    set have; *have is input data set name;

    *create an array to avoid listing all variables later;
    array vars_check(*) cusesability CUSESPurchase CUSESCarry CUSESDiscuss CUSESSuggest CUSESUse CUSESMaintain CUSESEmbarrass CUSESReject CUSESUnsure CUSESConfident CUSESComfort CUSESPersuade CUSESGrace CUSESSucceed;

    *calculate percent missing;
    Percent_Missing = NMISS(of vars_check(*)) / Dim(vars_check);

    if percent_missing >= 0.8 then exclude = 'Y';
    else exclude = 'N';

 run;

To replace with mean or a different method, PROC STDIZE can do that.

*temp is input data set name from previous step;
proc stdize data=temp out=temp_mean reponly method=mean;
*keep only records with more than 80%;
where exclude = 'N';

*list of vars to fill with mean;
VAR cusesability CUSESPurchase CUSESCarry CUSESDiscuss CUSESSuggest CUSESUse CUSESMaintain CUSESEmbarrass CUSESReject CUSESUnsure CUSESConfident CUSESComfort CUSESPersuade CUSESGrace CUSESSucceed;

run;

The different methods for standardization are here, but these are standardization methods not imputation methods.