I'm trying to run the simple query, but it's giving some syntax error. If I run it by removing the case when statement it runs fine which makes me feel the case when syntax is off. I have altered the table and variable names but apart from that the code is exact. I tried adding all sorts of brackets around the case statement but none of that seems to be working. Appreciate any help I can get. Thank you!
Sample Code:
proc sql;
create table abc as
select a.name, a.height, b.opendt,
case when today()-b.opendt>200 then b.opendt end as date_opened
from table1 a left join table2 b
on a.name=b.name
where (a.height>50 and b.prodcd = ' ');
quit;
Syntax error:
Syntax error: expected something between '(' and ')'.
Can you post the log
I don't find any issue with the code, it works fine with my sample data. Make sure that the data types you defined are same in the source tables.
prodcd - Is this a character variable, if its numeric then you might need to give proccd=. (period) for numeric missing value.
data table1;
set sashelp.class(keep=name height);
run;
data table2;
set sashelp.class(keep=name weight);
opendt='01JAN2018'd;
prodcd = ' ';
run;
proc sql;
create table abc as
select a.name, a.height, b.opendt,
case when today()-b.opendt>200 then b.opendt end as date_opened
from table1 a
left join table2 b
on a.name=b.name
where (a.height>50 and b.prodcd = ' ');
quit;
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.