x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 405

# comparing multiple variables equal to 1 in SAS

I have variables JAN, FEB, MAR, APR, MAY ........DEC
Is there a simple way to see if each of the respective variables is = 1 without using multiple "If statements"?
0
morinia
• 2
2 Solutions

Billing EngineerCommented:
you can put several conditions:

IF (JAN = 1 AND FEB = 1 AND MAR = 1 ... etc .. )
0

Commented:
are you looking for something like angelIII's answer or something else? if something else, could you be more specific about what you want?

a simple way, which is an alternative to angelIII's solution, is if you want to check if all variables holds value 1 is to do a sum, which if is anything but 12 would mean that one of the variables is not 1.
0

Billing EngineerCommented:
>is if you want to check if all variables holds value 1 is to do a sum, which if is anything but 12

well, that depends ...
if the values can be 0 and 1 only, yes, that will work.
if they can have other values also, this logic will eventually fail.
6x2 + 6x0 will give 12 also.

IF the values are all integer, then you could do the multiplication of all the values... and the result being 1 would imply all 12 values to be 1. if any was 0, the result would be 0, if any was > 1 otherwise, the result would be >1 ...
0

Thanks angelIII for the breakdown.  You are correct.  However, in this example I only have 0 and 1 in the field.  The field is initialized to 0 and updated to 1 if a criteria is met.

Your analytical breakdown is good to keep in mind, especially if there can be other values in the field.

Thanks again for the catch.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.