BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
underarmnat
Fluorite | Level 6

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;
set adherance;
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

data adherancescore;
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?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

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.

underarmnat
Fluorite | Level 6

Hi Astounding it contains a . for missing data

so that works,

 

Can you use arrays for the mean calculation?

 

Reeza
Super User

Yes, if it’s row wise. 

 

Mean(of var1-var6);

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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