## Arrays?

Solved
Occasional Contributor
Posts: 7

# Arrays?

I am trying to use an array to solve this problem, I have tried without but can't seem to get it

I have a adherence to medication scale compiled of responses to 6 questions,

My problem is I am only able to include participants in the final scale IF they have answered 4,5, or 6 Questions

I can't seem to come up with a formula that enables me to get rid of the people who have only answered 2 or 3 questions........

Here is my code

First I have reversed a few using array which had reverse scales

data reverse;
array reverse{*} q1 q2 q3;
do j= 1 to 3;
reverse{j}=6-reverse{j};
end;
run;

This reverses the 3 questions

Then without using array I can get the mean and multiply it by 6 to get scale score

set reverse;
adscalescore=mean(q1 q2 q3 q4 q5 q6)*6;

run;

This works but also calculates an average when only 2 or 3 have been scored...

Is it possible using array to exclude all except who answered 4,5 or 6 of q1-q6 and then calculate the total score of these?

Accepted Solutions
Solution
‎05-18-2018 10:02 PM
Super User
Posts: 6,644

## Re: Arrays?

Posted in reply to underarmnat

Well, you didn't specify what a question contains if somebody didn't answer it.  If an unanswered question contains a missing value, you could use:

if n(of q1-q6) > 3;

But if some other value, such as zero, represents "no answer", the programming would be different.

All Replies
Solution
‎05-18-2018 10:02 PM
Super User
Posts: 6,644

## Re: Arrays?

Posted in reply to underarmnat

Well, you didn't specify what a question contains if somebody didn't answer it.  If an unanswered question contains a missing value, you could use:

if n(of q1-q6) > 3;

But if some other value, such as zero, represents "no answer", the programming would be different.

Occasional Contributor
Posts: 7

## Re: Arrays?

Posted in reply to Astounding

Hi Astounding it contains a . for missing data

so that works,

Can you use arrays for the mean calculation?

Super User
Posts: 23,354

## Re: Arrays?

Posted in reply to underarmnat

Yes, if it’s row wise.

Mean(of var1-var6);

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
• 3 replies
• 179 views
• 1 like
• 3 in conversation