DATA Step, Macro, Functions and more

Creating Families indicators

Reply
Occasional Contributor
Posts: 10

Creating Families indicators

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;

Super User
Posts: 17,748

Re: Creating Families indicators

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. 

Super User
Posts: 5,071

Re: Creating Families indicators

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.

Super User
Posts: 17,748

Re: Creating Families indicators


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;


 

Ask a Question
Discussion stats
  • 3 replies
  • 114 views
  • 0 likes
  • 3 in conversation