4 Replies Latest reply on May 4, 2011 3:06 PM by LaRetta_1

    help with case statement

    kilbot

      Title

      help with case statement

      Post

      Here is what I have.

      What I need is to make the result a 0 if it is anything other than what I listed below.

      How can I do that?

      Case (ethnicity_gender_marker = "B";1;
      ethnicity_gender_marker = "D";1;
      ethnicity_gender_marker = "F";1;
      ethnicity_gender_marker = "H";1;
      ethnicity_gender_marker = "J";1;
      ethnicity_gender_marker = "L";1;)

      Thanks

        • 1. Re: help with case statement
          philmodjunk

          Case (ethnicity_gender_marker = "B";1;
          ethnicity_gender_marker = "D";1;
          ethnicity_gender_marker = "F";1;
          ethnicity_gender_marker = "H";1;
          ethnicity_gender_marker = "J";1;
          ethnicity_gender_marker = "L";1;
          /* else */ 0 )

          /* else */ is a comment and it can be left out if you prefer.

          • 2. Re: help with case statement
            kilbot

            Some reason it is leaving the 0 but none of the 1?

            • 3. Re: help with case statement
              philmodjunk

              Better check data and data types. That shouldn't happen unless ethnicity_gender_marker does not equal any of the letters you've used in quotes here. Keep in mind that an invisible character such as a space or a return will result in 0 here as the entire contents of the field is being compared to a single quoted letter.

              • 4. Re: help with case statement
                LaRetta_1

                It can also be written as:

                Case (
                ethnicity_gender_marker = "B" or
                ethnicity_gender_marker = "F" or
                ethnicity_gender_marker = "H" or
                ethnicity_gender_marker = "J" or
                ethnicity_gender_marker = "L";1; 0
                )

                Since this is the only field in the calculation and since you want a result of 0 to display if none of these characters exist, you must uncheck below in the calc dialog the ‘do not evaluate if all referenced fields are empty and this might be why you currently can't get the 0 result.  If this remains checked, it will not produce 0 if nothing at all is in the field.  Are those the records which don't produce 0 - the empty ones?

                You can also use a short Boolean test which will automatically display either 1 or 0 without unchecking 'do not evaluate' which is only one of the beauties of Boolean.

                not IsEmpty (  Filter (   "BFHJ" ; Upper ( ethnicity_gender_marker  ) ) )