Hello
I want to perform left join with a data set that is not existing.
I want to create a dynamic process that IF data set bbb doesn't exist then I will not get an error .
I get an error
"
37 QUIT;
____
22
76
ERROR 22-322: Syntax error, expecting one of the following: ',', GROUP, HAVING, ORDER, WHERE.
ERROR 76-322: Syntax error, statement will be ignored."
data aaa;
input id x;
cards;
1 10
2 20
3 30
;
run;
%macro xxx;
PROC SQL;
create table wanted as
select a.*,b.Y
from aaa as a
%if %sysfunc(exist(bbb)) %then
left join bbb as b
on a.id=b.id
;
QUIT;
%mend xxx;
%xxx;
You are missing a semicolon (one is needed to terminate the %IF, the other for the SQL SELECT).
Since SAS 9.4M6, you do not need a macro definition anymore:
proc sql;
create table wanted as
select a.*, b.Y
from aaa as a
%if %sysfunc(exist(bbb)) %then %do;
left join bbb as b
on a.id = b.id
%end;
;
quit;
Hello
I still recieve an error (I am using SAS enterprise guide 7.1)
data aaa;
input id x;
cards;
1 10
2 20
3 30
;
run;
proc sql;
create table wanted as
select a.*, b.Y
from aaa as a
%if %sysfunc(exist(bbb)) %then %do;
left join bbb as b
on a.id = b.id
%end;
;
quit;
/*ERROR: The %IF statement is not valid in open code.*/
%macro RRR;
proc sql;
create table wanted as
select a.*, b.Y
from aaa as a
%if %sysfunc(exist(bbb)) %then %do;
left join bbb as b
on a.id = b.id
%end;
;
quit;
%mend RRR;
%RRR;
/*ERROR: Unresolved reference to table/correlation name b.*/
You need to enclose
, b.y
in a similar ⁵IF-%THEN-%DO-%END block.
Thank you
Still got an error
___
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, ',', -, '.', /, <, <=, <>, =, >, >=, ?, AND, AS,
CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.
%macro RRR;
proc sql;
create table wanted as
select a.*,%if %sysfunc(exist(bbb)) %then %do; b.Y %end;
from aaa as a
%if %sysfunc(exist(bbb)) %then %do;
left join bbb as b
on a.id = b.id
%end;
;
quit;
%mend RRR;
%RRR;
Please pay attention to detsils!
You will see that the comma is part of the conditional code.
To be able to use %IF-%THEN %DO-%END in open code, you need to have the current maintenance level of SAS 9.4, which is M6. I mentioned that earlier.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.