- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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_").
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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_").
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Astounding! This worked, and I was apparently way overthinking this.