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?
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.
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.
Hi Astounding it contains a . for missing data
so that works,
Can you use arrays for the mean calculation?
Yes, if it’s row wise.
Mean(of var1-var6);
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.