Hi all:
I have the following dataset:
And I need to do an operation that does the following task:
For each ID, loop through the numeric array of variables A-D. Find the FIRST instance of when one of the array elements equals the target variable value. When that condition is met, replace the array element with a missing value.
So working above, the dataset would need to look like this:
Apologies for the lack of context, this is the final piece of a much larger undertaking but I can't wrap my head around the syntax:
This works so long as there is only one value that matches the target (Id 2), but in (Id 1), variables C and D are set to missing, where I only want C to be.
Any help is appreciated!
I have the following dataset:
Code:
ID A B C D Total Target
1 14 . 0 0 15 0
2 10 8 6 . 25 6
For each ID, loop through the numeric array of variables A-D. Find the FIRST instance of when one of the array elements equals the target variable value. When that condition is met, replace the array element with a missing value.
So working above, the dataset would need to look like this:
Code:
ID A B C D Total Target
1 14 . . 0 15 0
2 10 8 . . 25 6
Code:
data test2;
set test;
by id;
array g{4} A B C D;
do i = 1 to 4 until (g{i}=Target);
if g{i}=Target then g{i}=.;
end;
run;
Any help is appreciated!
Last edited: