Hi everyone,
I am new to SAS and a non-native English speaker so I apologize in advance if my question or sentences doesn't make sens.
I would like to refer to array variables in a sum function inside a do loop so that the value of the argument of the sum function changes at each iteration.
Here is an example of my data set:
ID
CUMBE1
CUMBE2
CUMBE3
CUMBE4
CUMBE5
CUMBE6
Valid
1
22
22
10
22
11
22
1
2
0
11
22
22
22
22
1
3
10
11
22
22
11
11
0
Where the variables CUMBE1 to 6 are the test results of 6 successive blood test, valid a variable that I would like to create. 0, 10 or 11 are valid results, 22 stand for missing value.
I would like to eliminate the individuals/observations for which more than one test is missing in between 2 valid tests. So if I have successive “22” at the beginning or at the end it is still valid, what we can’t have is a valid, 2 or more successive invalid and then a valid again, like in the third line of my example.
To do so, I tried to create a variable named “valid” that would equal 1 for the valid observations and 0 for the invalid. I tried several different codes and ways, including using 0/1 value instead of the numeric 0-10-11-22, by using the ARRAY statement.
At first I wanted SAS to count the number of "22" in between valid values, and if >1 valid =0, but I couldn’t find how to do so.
So I tried here to tell SAS that if the sum of the array-variables in-between 2 valid values > 44 (that is at most 11+ 22+ 11 ), then it is not valid.
Here is my last try:
data IBR.validA;
set IBR.valid1;
validA=1;
array cum{6} cumBE1-cumBE6;
do i=1 to 6;
do n=1 to 5 while (i+n<7);
if cum{i}<22 and cum{i+n}<22 and sum(of cum{i}-cum{i+n})>44 then
do;
validA=0;
leave;
end;
else;
end;
if validA=0 then
do;
leave;
end;
end;
run;
And this is the message in the log:
53 do n=1 to 5 while (i+n<7);
54 if cum{i}<22 and cum{i+n}<22 and sum(of cum{i}-cum{i+n})>44 then
-
22
ERROR 22-322: Syntax error, expecting one of the following: ), ','.
I mean sum values from cum{i} to cum{i+n}. But if I don’t put the “of” in the sum function, then SAS operates a subtraction of cum{i} minus {i+n} and gives me only valid value.
How can I do for SAS to read the expression “cum{i} – cum{i+n}” as a SAS variable list expression and not as a subtraction? Or is there an other function I could use to sum/to take into account only a part of the array-variables and not all of them (which "sum(of cum{i})" does) ?
Or, even better, is there maybe a more easiest way of doing this task?
Thanks a lot for any help!
Do not hesitate too tell me if my question is not clear, I’ll try explain it another way
... View more