BookmarkSubscribeRSS Feed
astha8882000
Obsidian | Level 7

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 ')'.

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Can you post the log

SuryaKiran
Meteorite | Level 14

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;

 

Thanks,
Suryakiran

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 566 views
  • 0 likes
  • 3 in conversation