Given:

If a variable is coded from 1 to 10 and can hold any number values, then we have two problems:

a) parsing out the values

b) differentiating between ‘1’ and ’10’

For example, lets say we have a variable CD18 that is defined as “Who took the blood sugar?”, and we allow the participant to answer “check all that apply”:

(1) Mother               (2) Father

(3) Grandmother      (4) Grandfather

(5) Sister                 (6) Brother

(7) Aunt                   (8) Uncle

(9) Other Relative      (10) Non-Relative

The problem is that SAS will import a string of values.  In Python we might call it a list of strings. For example if the Mother and Sister had recorded the blood sugar, CD18 might = “15”, however if the Father had taken the measurement then CD18 is coded “2”. What happens if the participant indicated a non-relative?

If you parse for the presence of a ‘1’ in the string, you will miss information or could have a misclassification bias. Instead you need to use logic statements to better parse the data.

/* SCANNING for Mother */

IF CD18 = ” THEN CD18_mother = .;

ELSE IF (Index(CD18, ‘1’) ^=0) AND (Substr(CD18,2,1) ^= “0”) THEN CD18_mother = 1;

ELSE CD18_mother =0;

/* SCANNING for Father */

IF CD18 = ” THEN CD18_father = .;

ELSE IF Index(CD18, ‘2’) ^=0 THEN CD18_father = 1;

ELSE CD18_father =0;

/* SCANNING for Grandmother */

IF CD18 = ” THEN CD18_grandmother = .;

ELSE IF Index(CD18, ‘3’) ^=0 THEN CD18_grandmother = 1;

ELSE CD18_grandmother =0;

/* SCANNING for Grandfather */

IF CD18 = ” THEN CD18_grandfather = .;

ELSE IF Index(CD18, ‘4’) ^=0 THEN CD18_grandfather = 1;

ELSE CD18_grandfather =0;

/* SCANNING for Sister */

IF CD18 = ” THEN CD18_sister = .;

ELSE IF Index(CD18, ‘5’) ^=0 THEN CD18_sister = 1;

ELSE CD18_sister =0;

/* SCANNING for Brother */

IF CD18 = ” THEN CD18_brother = .;

ELSE IF Index(CD18, ‘6’) ^=0 THEN CD18_brother = 1;

ELSE CD18_brother =0;

/* SCANNING for Aunt */

IF CD18 = ” THEN CD18_aunt = .;

ELSE IF Index(CD18, ‘7’) ^=0 THEN CD18_aunt = 1;

ELSE CD18_aunt =0;

/* SCANNING for Uncle */

IF CD18 = ” THEN CD18_uncle = .;

ELSE IF Index(CD18, ‘8’) ^=0 THEN CD18_uncle = 1;

ELSE CD18_uncle =0;

/* SCANNING for Other-Relative */

IF CD18 = ” THEN CD18_other = .;

ELSE IF Index(CD18, ‘9’) ^=0 THEN CD18_other = 1;

ELSE CD18_other =0;

/* SCANNING for Non-Relative */

IF CD18 = ” THEN CD18_non = .;

ELSE IF Index(CD18, ‘0’) ^=0 THEN CD18_non = 1;

ELSE CD18_non =0;

Advertisement