I am trying to use this code, everything is working perfectly except for FAM_E, anyone can help me
data merged;
set merged;
BY FAMID;
if FIRST.FAMID THEN DO;
FAM_A = 0;
FAM_B = 0;
FAM_C = 0;
FAM_D = 0;
FAM_E = 0;
FAM_F = 0;
FAM_G = 0;
END;
IF (EFNP EQ 1) AND (adult eq 1)
THEN DO;
FAM_A = 1;
FAM_B = 0;
FAM_C = 0;
FAM_D = 0;
FAM_E = 0;
FAM_F = 0;
FAM_G = 0;
END;
ELSE IF (RHTYPE EQ 3) AND (EFNP GE 2) AND (under18 eq 1) AND (adult eq 1)
THEN DO;
FAM_A = 0;
FAM_B = 1;
FAM_C = 0;
FAM_D = 0;
FAM_E = 0;
FAM_F = 0;
FAM_G = 0;
END;
ELSE IF (RHTYPE EQ 2) AND (EFNP GE 2) AND (under18 eq 1) AND (adult eq 1)
THEN DO;
FAM_A = 0;
FAM_B = 0;
FAM_C = 1;
FAM_D = 0;
FAM_E = 0;
FAM_F = 0;
FAM_G = 0;
END;
ELSE IF (EFNP GE 2) AND (adult eq 1)
THEN DO;
FAM_A = 0;
FAM_B = 0;
FAM_C = 0;
FAM_D = 1;
FAM_E = 0;
FAM_F = 0;
FAM_G = 0;
END;
ELSE IF (EFNP gt 2) AND (adult eq 1) AND (under18 eq 1) and (over64 eq 0)
THEN DO;
FAM_A = 0;
FAM_B = 0;
FAM_C = 0;
FAM_D = 0;
FAM_E = 1;
FAM_F = 0;
FAM_G = 0;
END;
ELSE IF (EFNP GT 2) AND (under18 eq 1) AND (over64 eq 1)
THEN DO;
FAM_A = 0;
FAM_B = 0;
FAM_C = 0;
FAM_D = 0;
FAM_E = 0;
FAM_F = 1;
FAM_G = 0;
END;
ELSE IF (EFNP ge 1) AND (over64 eq 1)
THEN DO;
FAM_A = 0;
FAM_B = 0;
FAM_C = 0;
FAM_D = 0;
FAM_E = 0;
FAM_F = 0;
FAM_G = 1;
END;
ELSE IF (RHTYPE EQ .) AND (EFNP EQ .) AND (under18 eq .) AND (OVER64 EQ .) and (adut eq .)
THEN DO;
FAM_A = .;
FAM_B = .;
FAM_C = .;
FAM_D = .;
FAM_E = .;
FAM_F = .;
FAM_G = .;
END;
if LAST.FAMID THEN OUTPUT;
Retain Fam_A Fam_B Fam_C Fam_D Fam_E Fam_F Fam_G;
This occurs when your conditions overlap in some manner. Identify some of your E records manually, see where theyre getting coded and compare your conditions, noting that once a condition is met in a series of IF/THEN statements the remaining are not evaluated.
Your conditions for setting up FAM_D already include all the FAM_E observations. There is nothing left for ELSE to process that might become FAM_E=1.
@Mike7 wrote:
I am trying to use this code, everything is working perfectly except for FAM_E, anyone can help me
data merged;
set merged;
BY FAMID;
if FIRST.FAMID THEN DO;
FAM_A = 0;
FAM_B = 0;
FAM_C = 0;
FAM_D = 0;
FAM_E = 0;
FAM_F = 0;
FAM_G = 0;
END;
IF (EFNP EQ 1) AND (adult eq 1)
THEN DO;
FAM_A = 1;
FAM_B = 0;
FAM_C = 0;
FAM_D = 0;
FAM_E = 0;
FAM_F = 0;
FAM_G = 0;
END;
ELSE IF (RHTYPE EQ 3) AND (EFNP GE 2) AND (under18 eq 1) AND (adult eq 1)
THEN DO;
FAM_A = 0;
FAM_B = 1;
FAM_C = 0;
FAM_D = 0;
FAM_E = 0;
FAM_F = 0;
FAM_G = 0;
END;
ELSE IF (RHTYPE EQ 2) AND (EFNP GE 2) AND (under18 eq 1) AND (adult eq 1)
THEN DO;
FAM_A = 0;
FAM_B = 0;
FAM_C = 1;
FAM_D = 0;
FAM_E = 0;
FAM_F = 0;
FAM_G = 0;
END;
ELSE IF (EFNP GE 2) AND (adult eq 1)
THEN DO;
FAM_A = 0;
FAM_B = 0;
FAM_C = 0;
FAM_D = 1;
FAM_E = 0;
FAM_F = 0;
FAM_G = 0;
END;
ELSE IF (EFNP gt 2) AND (adult eq 1) AND (under18 eq 1) and (over64 eq 0)
THEN DO;
FAM_A = 0;
FAM_B = 0;
FAM_C = 0;
FAM_D = 0;
FAM_E = 1;
FAM_F = 0;
FAM_G = 0;
END;
ELSE IF (EFNP GT 2) AND (under18 eq 1) AND (over64 eq 1)
THEN DO;
FAM_A = 0;
FAM_B = 0;
FAM_C = 0;
FAM_D = 0;
FAM_E = 0;
FAM_F = 1;
FAM_G = 0;
END;
ELSE IF (EFNP ge 1) AND (over64 eq 1)
THEN DO;
FAM_A = 0;
FAM_B = 0;
FAM_C = 0;
FAM_D = 0;
FAM_E = 0;
FAM_F = 0;
FAM_G = 1;
END;ELSE IF (RHTYPE EQ .) AND (EFNP EQ .) AND (under18 eq .) AND (OVER64 EQ .) and (adut eq .)
THEN DO;
FAM_A = .;
FAM_B = .;
FAM_C = .;
FAM_D = .;
FAM_E = .;
FAM_F = .;
FAM_G = .;
END;
if LAST.FAMID THEN OUTPUT;
Retain Fam_A Fam_B Fam_C Fam_D Fam_E Fam_F Fam_G;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.