## IF/THEN STATEMENTS: Multiple Conditions in an Array

Solved
Frequent Contributor
Posts: 79

# IF/THEN STATEMENTS: Multiple Conditions in an Array

Hello everyone,

I am trying to create a summary score based on eight dichotomous variables (labelled 1/2 instead of 0/1 since I am going to be doing my regression analysis in SUDAAN). Each of the variables has missing values and I would like my array to show that IF there are more than four missing values between the eight variables for a single observation THEN the observation is read as missing. Otherwise, if there are less than four missing values between the eight variables, then the score will be between 1-8.

This is what my array looks like at the moment (a shoutout to PhilC for helping fix my array) and it works for giving me a sum score between 1-8.

ARRAY ACE_ARRAY[8]  ACEPRISN2 ACEDIVRC2 ACEDEPRS2 ACESXAB ACESUBS ACEPUNCH2 ACESWEAR2 ACEHURT2;

SUM_ACESCORE = 0;

do i=1 to 8; drop i;

SUM_ACESCORE+ACE_ARRAY;

end;

I assume you can use some type of IF/THEN statement in the DO loop to do this, but I cannot figure out how to signify "four or more missing values".

As always Thank you guys for your help!

Donald S.

Accepted Solutions
Solution
‎08-04-2015 10:26 AM
Super User
Posts: 9,599

## Re: IF/THEN STATEMENTS: Multiple Conditions in an Array

Hi,

Correction, use the nmiss() function

ARRAY ACE_ARRAY[8]  ACEPRISN2 ACEDIVRC2 ACEDEPRS2 ACESXAB ACESUBS ACEPUNCH2 ACESWEAR2 ACEHURT2;

SUM_ACESCORE = 0;

do i=1 to 8; drop i;

if nmiss(of ace_array{*})<4 then SUM_ACESCORE+ACE_ARRAY;

end;

Also, try to use lower case in SAS code.

All Replies
Solution
‎08-04-2015 10:26 AM
Super User
Posts: 9,599

## Re: IF/THEN STATEMENTS: Multiple Conditions in an Array

Hi,

Correction, use the nmiss() function

ARRAY ACE_ARRAY[8]  ACEPRISN2 ACEDIVRC2 ACEDEPRS2 ACESXAB ACESUBS ACEPUNCH2 ACESWEAR2 ACEHURT2;

SUM_ACESCORE = 0;

do i=1 to 8; drop i;

if nmiss(of ace_array{*})<4 then SUM_ACESCORE+ACE_ARRAY;

end;

Also, try to use lower case in SAS code.

Frequent Contributor
Posts: 79

## Re: IF/THEN STATEMENTS: Multiple Conditions in an Array

Worked like a charm! Thank you RW9.

I feel like every time someone helps me figure out a problem on here I learn something new and very useful!

🔒 This topic is solved and locked.