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
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
  • 2 replies
  • 889 views
  • 0 likes
  • 3 in conversation