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: 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
  • 4 replies
  • 657 views
  • 1 like
  • 5 in conversation