BookmarkSubscribeRSS Feed
hcstritz
Calcite | Level 5

I'm working through the SAS SQL I: Essentials training videos and I'm a bit confused about the terminology of the two different forms of the CASE expressions.

 

Here is how the video/course materials describe the "simple expression":

 

"Let's start with the standard form CASE expression, or simple CASE expression. With this syntax, you can use equality and non-equality tests for validity.

 

SELECT col-name, col-name
        CASE <case-operand>
                   WHEN when-condition THEN result-expression
                   <WHEN when-condition THEN result-expression...>
                   <ELSE result-expression>

        END <AS column>

 

The "case-operand form" is then described as:

 

"You can also construct a CASE expression by using the CASE-OPERAND form. You specify the condition as the case-operand once at the top of the CASE expression, followed by a series of WHEN-THEN clauses. Here, we select the Married column, and based on the values, we assign them to a specified category.

When you use the CASE-OPERAND form of the CASE expression, the conditions must all be equality tests. That is, they cannot use comparison operators or other types of operators."

 

Unless I'm mistaken, it seems that this distinction between "simple form" versus "case-operand form" is different than the "simple case" versus "searched case" forms used in other SQL variants. For example, what the SAS training calls "simple form" corresponds to the "searched case" form and the "case-operand form" corresponds to the "simple case form" as documented by the ANSI-compliant IBM DB product:  https://www.ibm.com/docs/en/db2-warehouse?topic=statements-case-statement-in-sql-procedures

 

The SAS 9.4 documentation doesn't appear to make the distinction between "simple form" and "case-operand form." It seems confusing to call them that in the training/videos when these definitions don't adhere to more standard SQL terminology. 

1 REPLY 1
Tom
Super User Tom
Super User

I could not find the old original ANSI Standard SQL from 1992 that SAS PROC SQL is based on to check, but it looks like you are right that others are applying the term "simple" (usually in quotes) to the expression/value version of the CASE syntax.

 

Personally I don't find either of them simple, but in my experience the version where each WHEN clause has a boolean expression instead of a value is the "normal" way that CASE expressions are used.

Welcome to the Certification Community

 

This is a knowledge-sharing community for SAS Certified Professionals and anyone who wants to learn more about becoming SAS Certified. Ask questions and get answers fast. Share with others who are interested in certification and who are studying for certifications.To get the most from your community experience, use these getting-started resources:

Community Do's and Don'ts
How to add SAS syntax to your post
How to get fast, helpful answers

 

Why Get SAS Certified.jpg

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 222 views
  • 0 likes
  • 2 in conversation