Hi all,
So I'm looking at a dataset similar to this:
data sample;
input var1 $ var2 $ var3 $ var4 $ x1 $ x2 $ x3 $ x4 $;
datalines
a b c d 9 8 7 6
b c d e 8 7 6 5
c d e f 7 6 5 4
d e f g 6 5 4 3
e f g h 5 4 3 2
f g h i 4 3 2 1
g h i j 3 2 1 0
;
run;
In this case I'm trying to detect whether var1 - var4 has an "e" or "f" in it and if x1 - x4 has a "7" or "2" in it. My code to process this is similar to the following:
data record;
set sample;
array var {4} $ var1-var4;
array x {4} $ x1-x4;
array cond (2) cond1-cond2 (2*0);
do i=1 to 4;
if var[i] in ("e", "f") then cond1=1;
if x[i] in ("7", "2") then cond2=1;
end;
drop i;
run;
Now my problem, I start by initializing each cond# to 0, but once the do loop meets the first valid condition (for either var[i] or x[i]) then the cond# will equal 1 from that point on and won't reset to 0. I don't think I can reset to 0 in the do loop as the cond# value would switch to 0 upon meeting a new var[i] or x[i] that does not meet the criteria.
Any idea how I might be able to get the cond# back to 0? Or if I'm wrongly implementing my code? Thanks!
This is a simplified version of what I'm working on, but the structure and implementation of the code is the same. What's different is the number of conditional values, number of array variables, and number of observations.
why do u want to reset to 0
There's nothing in the simplified code that you have shown that would do this. In the more complex version:
There isn't an apparent reason to set COND1 and COND2 to zero. Leaving them as missing would be OK, at least for the abbreviated code that you posted. In fact, there is no apparent reason for adding COND1 and COND2 to an array. The array name is never used.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.