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.
from table b as aa1
in the above which is alias?
if aa1 is alias then what is b?
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
,...
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.