Now we can take advantage of the 0/1 coding to use a simple expression to calculate the COUNT of how many are TRUE when INDEX is TRUE like this:
data want;
set have;
count=index*sum(of variable1-variable3);
run;
If instead of a COUNT you actual want another boolean flag then use the MAX() function instead of the SUM() function. Or replace the * operator with the AND operator instead.
Result:
3162 proc print;
3163 where count ne expect;
3164 run;
NOTE: No observations were selected from data set WORK.WANT.
NOTE: There were 0 observations read from the data set WORK.WANT.
WHERE count not = expect;
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
Seems as if when INDEX=1, you want to test to see if there is a 1 in variable1-variable3. Testing these three variables is a simple series of IF statements, or better yet you can use the SUM function
if sum(of variable1-variable3)>0 then ... ;
else ... ;
Now we can take advantage of the 0/1 coding to use a simple expression to calculate the COUNT of how many are TRUE when INDEX is TRUE like this:
data want;
set have;
count=index*sum(of variable1-variable3);
run;
If instead of a COUNT you actual want another boolean flag then use the MAX() function instead of the SUM() function. Or replace the * operator with the AND operator instead.
Result:
3162 proc print;
3163 where count ne expect;
3164 run;
NOTE: No observations were selected from data set WORK.WANT.
NOTE: There were 0 observations read from the data set WORK.WANT.
WHERE count not = expect;
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
SAS Innovate 2025: Register Now
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9. Sign up by Dec. 31 to get the 2024 rate of just $495. Register now!