BookmarkSubscribeRSS Feed
Mike7
Calcite | Level 5

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;

3 REPLIES 3
Reeza
Super User

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. 

Astounding
PROC Star

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.

Reeza
Super User

@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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 767 views
  • 0 likes
  • 3 in conversation