BookmarkSubscribeRSS Feed
kajal_30
Quartz | Level 8

proc sql;
select name into : table
from country.DETAIL
where ID = 34
and CD = "abc"
;
quit;

 

proc sql;
select name into : table
from country.DETAIL
where ID = &first_id.
and CD = "abc"
;
quit;

 

First query is running fine and second throwing error:

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, '.', /, <, <=, <>, =, >, >=, AND, EQ, EQT,
GE, GET, GROUP, GT, GTT, HAVING, LE, LET, LT, LTT, NE, NET, OR, ORDER, ^=, |, ||, ~=.

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

can you please help why hard coding macro variable value is not giving any error but macro variable is giving error

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

Ideally it should not give error, could you please check the if the macro variable first_id is having the values

Please execute below code and check if it resolves to any value

 

%put &first_id;
Thanks,
Jag
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @kajal_30 

 

You get this error if the macro variable first_id exists, but is assigned an empty value. It resolves to blank in the select, and the where-statement becomes where ID = and CD = "abc", which is illegal syntax.

Astounding
PROC Star
We can't see how &FIRST_ID was created. If that was done using macro quoting functions, it may contain unprintable characters that SQL doesn't detect and remove in time. If that's what happened, you need to remove those characters yourself:

where id = %unquote(&first_id.)

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
  • 697 views
  • 1 like
  • 5 in conversation