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
The 2025 SAS Hackathon Kicks Off on June 11!
Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.