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

Hello,

 

I'm trying to use an array and 'do loop' to create a new summary variable based on the evaluation of all the array variables, but the result I get is based on only the last variable in the array. Basically, I'm trying to evaluate 6 variables to determine the value of 1 new variable.

 

I have 6 genetic test status result variables: 'OverallTestStatus_Result_1' through 'OverallTestStatus_Result_6', and they are coded -1="True Negative; 0="Variant"; and 1="True Positive". My data has 1 record per Subject.

 

If a Subject has a "True Positive" (code 1) for ANY of their 6 result variables, then they should get a value of 1 (Positive) for the new summary variable 'genetic_test_summary'.

 

If a Subject doesn't have a "True Positive" (code 1) for ANY of their 6 result variables, but they do have a "Variant' (coded 0) for ANY of their 6 result variables, then they should get a value of 0 (Variant) for the new variable 'genetic_test_summary'.

 

And finally, if a Subject has a "True Negative" (code -1) for ALL of their 6 result variables, then they should get a value of -1 (Negative) for the new summary variable 'genetic_test_summary'.

 

I thought that using 'else if' would work to address the ANY vs. ALL requirement/condition for the different summary variable value scenarios, but it does not.

 

Can this be done with a 'do loop'? How do I evaluate every element of the array, not just the last, and is there a way to evaluate different array elements with 'AND' or 'OR'?

 

A snip of my code is below, but it doesn't work. If a subject has a "True Positive" (code 1) for their first 5 result variables, and the 6th result variable is a "Variant" (code 0), then the summary variable 'genetic_test_summary' gets coded 0 (Variant).

 

/* Creating a summary variable (for anyone tested)       */
/* to denote  "Positive" (any overallteststatus that     */
/* includes a "True positive"); and if all true negative */
/* then it would be coded be as "Negative"; if there is  */
/* a variant, would be "variant" (except if there was    */
/* also a positive test result, then this would trump    */
/* "variant").                                           */

array OverallTestStatusArr {6} OverallTestStatus_Result_1 OverallTestStatus_Result_2 OverallTestStatus_Result_3
                               OverallTestStatus_Result_4 OverallTestStatus_Result_5 OverallTestStatus_Result_6;

do i = 1 to 6 while(OverallTestStatusArr{i} ne .);
       if OverallTestStatusArr{i}=1 then genetic_test_summary=1; /* Positive */
  else if OverallTestStatusArr{i}=0  then genetic_test_summary=0; /* Variant */
  else if OverallTestStatusArr{i}=-1 then genetic_test_summary=-1; /* Negative */
end;
drop i;

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You have to decide what to do if there might be missing values in the data.  Other than that, a single statement should compute the result you are asking for:

 

genetic_test_summary = max(of Overall_Test_Status_Result_: );

 

This assumes that the six variables you mention are the only ones with names that begin with "Overall_Test_Status_Result_").

View solution in original post

2 REPLIES 2
Astounding
PROC Star

You have to decide what to do if there might be missing values in the data.  Other than that, a single statement should compute the result you are asking for:

 

genetic_test_summary = max(of Overall_Test_Status_Result_: );

 

This assumes that the six variables you mention are the only ones with names that begin with "Overall_Test_Status_Result_").

gkirkner
Calcite | Level 5

Thanks, Astounding! This worked, and I was apparently way overthinking this.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 988 views
  • 3 likes
  • 2 in conversation