BookmarkSubscribeRSS Feed
belboy
Obsidian | Level 7

Hi SAS community,

I'm working on some code and getting a weird error.

 

My SAS Log:

 

aa1.bky_filing_dt,
57 aa1.bky_remvl_dt,
58 aa1.bky_chapter,
59 aa1.last_ansys_eff_date,
60 aa1.ESCROW_OVERAGE_SHORTAGE,
61
62 case when aa1.bky_filing_dt is not null
____
22
76
ERROR 22-322: Syntax error, expecting one of the following: a name, (, ), ',', '.', ANSIMISS, AS, CROSS, FULL, INNER, JOIN, LEFT,
NATURAL, NOMISS, RIGHT.

ERROR 76-322: Syntax error, statement will be ignored.

63 then aa1.bky_filing_dt
64 else Min(aa1.Load_Date) end as sort,

 

 

My proc sql code includes this case when statement which seems to be generating the error.

select

aa1.loan_no,
min(aa1.load_date) as min_load_dt,
max(aa1.load_date) as max_load_dt,
aa1.unique_id,
aa1.bky_filing_dt,
aa1.bky_remvl_dt,
aa1.bky_chapter,
aa1.last_ansys_eff_date,
aa1.ESCROW_OVERAGE_SHORTAGE,

case when aa1.bky_filing_dt is not null
then aa1.bky_filing_dt
else Min(aa1.Load_Date) end as sort

 

from table b as aa1; quit;

 

I'm simply trying to create a column named 'sort' that will use bky_filing_dt if the column isn't null, or use aa1.load_date.  Why is SAS giving me this error?  

 

Thanks for any suggestions that will help.

4 REPLIES 4
novinosrin
Tourmaline | Level 20

from table b as aa1

 

in the above which is alias?

if aa1 is alias then what is b?

belboy
Obsidian | Level 7
Sorry. TableB as aa1 ##- Please type your reply above this line. No
attachments. -##
ScottBass
Rhodochrosite | Level 12

Not exactly an answer to your error, but related...

 

Investigate the COALESCE function.  Your code would change from:

 

case when aa1.bky_filing_dt is not null
then aa1.bky_filing_dt
else Min(aa1.Load_Date) end as sort

To:

 

SELECT
...
,COALESCE(aa1.bky_filing_dt, MIN(aa1.Load_Date)) as sort
,...

Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
PGStats
Opal | Level 21

That code looks correct. You might be stuck with some nonprinting character in your code. try removing a couple of lines and retyping them anew.

PG

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 13516 views
  • 0 likes
  • 4 in conversation