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);

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 858 views
  • 1 like
  • 3 in conversation