Exampler.org SAS PYTHON HTML
SAS Introduction
SAS Abs
SAS Anydigit
SAS ASC
SAS Case Stmnt.
SAS Ceiling
SAS Change type
SAS Char
SAS CMISS
SAS Coalesc
SAS Coalescec
SAS Concatenate
SAS Constant
SAS Create Table
SAS DateTime
SAS Day
SAS Find
SAS Floor
SAS HMS
SAS Holiday
SAS HOUR
SAS Import
SAS Informats
SAS Inobs
SAS Input Stmt.
SAS Int
SAS INTNX
SAS Length
SAS Libname
SAS Loops
SAS Minute
SAS Month
SAS MDY
SAS NMISS
SAS Notdigit
SAS Lowercase
SAS Outobs
SAS Put Stmt.
SAS Rename
SAS Round
SAS Scan
SAS Substr
SAS Sum
SAS STNAME
SAS STNAMEL
SAS Time
SAS Trunc
SAS Uppercase
SAS Week
SAS Year
SAS Financial Functions
SAS Compound

SAS Case Statement

What is it?

Syntax:

CASE Field_being_evaluated
        when condition_1 then condition_result
        when condition_2 then condition_result_2
        else condition_result_3
        end as name_of_column

Case Statement:

Example:



libname ABCDEFGH postgres server="Server_Address.com" port=5432 user=kevin password="P@ssW0rd" database=DBName schema=SchemaName;


Proc SQL;
   Select first_name, last_name, relationship_status,
         case relationship_status
               when relationship_status = Single then "Seating for 1"
               when relationship_status = Married then "Seating for 2"
               else "Unknown" end as Status
   from ABCDEFG.your_table;

Quit;


What's happening in the script above?

  • Libname is the connection string to the database and schmema that has your information in it.
  • Proc sql; is the beginning of all SAS scripts; with some exceptions
  • Case comes after the comma as if it's just another column being added. It also has the column name you'd like to evaluate
  • When and Then are the scenarios and results your testing (e.g. when the relationship status is Married, the answer should be Seating for 1)


Results:

first_name last_name relationship_status Status
Kevin Regan Married Seating for 2
John Doe Single Seating for 1
Jane Adams Unknown
Jada Smith Entanglement Unknown






Connect via LinkedIn

Kevin Regan

Have an article, idea, found a typo, want to contribute? Shoot me an email Here


Below are links to some Udemy Data Science Courses. I've been using Udemy for a number of years now, and I've found their courses super helpful, maybe you will also.