BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

Hello team,

I need to use or statement in a case statement. It keeps giving me errors:

Proc sql;
create table mytable as;

select a.*, b* ,
case when (a.diagcode1 <150  and a.diagcode2 <12) then 'no more'
case when missing(a.diagcode) or missing(a.diacode2) then 'non existent'
else ' '
end as 'new stata'
from a Left join b...



what is the problem?

Regards

blueblue

Blue Blue
4 REPLIES 4
SASKiwi
PROC Star

Try this - but please remember to post your SAS log including errors as we aren't mind readers 😉

Proc sql;
create table mytable as

select a.*, b* ,
case 
when (a.diagcode1 <150 and a.diagcode2 <12) then 'no more' when missing(a.diagcode) or missing(a.diacode2) then 'non existent' else ' ' end as new_stata from a Left join b...
Reeza
Super User
1. Too many CASE (twice, should only be once) One CASE per new variable being created.
2. Too early semicolon - no semicolon after the AS on the CREATE TABLE clause
3. Order of operations. SAS puts numeric missing as the lowest values so if you first check if the values are < 12 and 150 and both are missing you'll get them coded into "no more" when it should be in non existent.

Those are for starters...there could be more.
Reeza
Super User
And if there are errors in your code include them in the post.
PGStats
Opal | Level 21

Also

 

as 'new stata'

should be

as 'new strata'n
PG

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 2862 views
  • 1 like
  • 4 in conversation