I have been trying to work on this code (SAS 9.4) and I am not sure where I am messing up. I know that I need to use an array-do loop but I am unsure if it needs to be a nested array-do loop. My goal is to search through all 8 food codes (i.e., Variable Name: OAT_1, OAT_2, OAT_3, etc.). A person should be considered a case if they have at least two food codes that fall into the following ranges 900-1059 (excluding 1005-1009, 1010-1024, and 1030-1039). Also, I am only taking the first three numbers of each value in the dataset and I need to use the substring function. This is what I have so far: DATA <> SET <> ARRAY Case(8)$ OAT_1-OAT_8; CASE = 0; DO i = 1 to 8; IF 900 <= SUBSTR (Case(i), 1, 3) <= 1005 THEN CASE = 1; IF 1025 <= SUBSTR (Case(i), 1, 3) <= 1029 THEN CASE = 1; IF 1040 <= SUBSTR (Case(i), 1, 3) <= 1059 THEN CASE = 1; Do j = 1 to 8; IF 900 <= SUBSTR (Case(j), 1, 3) <= 1005 THEN CASE = 1; IF 1025 <= SUBSTR (Case(j), 1, 3) <= 1029 THEN CASE = 1; IF 1040 <= SUBSTR (Case(j), 1, 3) <= 1059 THEN CASE = 1; END; END; RUN; Each time I submit this code, I see observations that should be coded as a non-case coded as a '1' (i.e., case). I have also tried to make the IF/THEN statement under the DO j = 1 to 8 have CASE = 2, but it is still incorrectly coded.
... View more