BookmarkSubscribeRSS Feed
SAS241
Calcite | Level 5
I get this error in this portion of my code:
proc sql;
Create table test as
…,
(Case when Brangen = ‘1’ then ‘Gen’
when Brangen = ‘2’ then ‘Bran’
when Brangen = ‘3’ then ‘Undet’ else ‘E’ end ) as Flag
,
….

The format of Brangen is character
How do I fix this error:
A case expression has no else clause, cases not accounted for by the when clauses will result in a missing value for the Case expression.

5 REPLIES 5
SASKiwi
PROC Star

That is not a SAS ERROR, it is a SAS NOTE:

 

NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will result in a missing value for the CASE
expression.

 

Your program will continue to run OK. If you want to avoid these notes then just add an ELSE.

 

SAS241
Calcite | Level 5
There is already an Else in my code
SASKiwi
PROC Star

There must be an issue with your syntax then. Please post your complete SAS log if you want further help.

Tom
Super User Tom
Super User

@SAS241 wrote:
There is already an Else in my code

So either the ELSE is missing in a different CASE clause in your current query.

Or your current query is exercising a VIEW that has the incomplete CASE clause.  Example:

2634  proc sql;
2635  create view v1 as
2636    select *,case when sex='M' then 'Male' when sex='F' then 'Female' end as gender
2637    from sashelp.class
2638  ;
NOTE: SQL view WORK.V1 has been defined.
2639  select name,sex,gender from v1;
NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will result in a missing value for the CASE
      expression.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 737 views
  • 1 like
  • 4 in conversation