Hi all,
a simple question:
while trying to run a proc fedsql inside a call execute loop i'm getting a strange error:
data _null_; a= "MD"; set GNC.GNC_CAUSES_NO_EDGE_BACK(obs=1); call execute('proc fedsql sessref=EG_Session; select distinct id_remi from GNC.REMI_VOL_2008_2021_FINAL where id_class ='||a||'; quit;'); run;
BTW: the dataset live in a cas library
I'm getting this error:
NOTE: There were 1 observations read from the data set GNC.GNC_CAUSES_NO_EDGE_BACK. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds NOTE: CALL EXECUTE generated line. 1 + proc fedsql sessref=EG_Session; select distinct id_remi from GNC.REMI_VOL_2008_2021_FINAL where id_class =MD; 1 + quit; ERROR: Column "MD" not found or cannot be accessed ERROR: Azione interrotta a causa di errori. ERROR: The FedSQL action was not successful. NOTE: PROC FEDSQL has set option NOEXEC and will continue to prepare statements. NOTE: PROCEDURE FEDSQL used (Total process time): real time 0.00 seconds cpu time 0.01 seconds
I've tested the same code using proc SQL, with no problem, but since the main table is huge i would like to use fedsql (much faster)
I'm on viya 3.5 executed from a local SAS session.
PROC FEDSQL is probably treating "MD" as a variable reference and is expecting you to use single quotes for literals. In PROC SQL you have to request this behavior but perhaps it is the default in PROC FEDSQL.
Tell the QUOTE() function to use single quotes.
quote(a,"'")
Pretty clear:
1 + proc fedsql sessref=EG_Session; select distinct id_remi from GNC.REMI_VOL_2008_2021_FINAL where id_class =MD;
No quotes around MD means SAS is using it as a variable not a literal value.
You want to generate
proc fedsql sessref=EG_Session; select distinct id_remi from GNC.REMI_VOL_2008_2021_FINAL where id_class ='MD';
which might be easiest with
call execute('proc fedsql sessref=EG_Session; select distinct id_remi from GNC.REMI_VOL_2008_2021_FINAL
where id_class ='|| quote(a) ||'; quit;');
Even stranger now:
after using your suggestion, I'm getting the same error:
NOTE: CALL EXECUTE generated line. 1 + proc fedsql sessref=EG_Session; select distinct id_remi from GNC.REMI_VOL_2008_2021_FINAL where id_class ="MD"; 1 + quit; ERROR: Column "MD" not found or cannot be accessed ERROR: Azione interrotta a causa di errori. ERROR: The FedSQL action was not successful.
It still says that it can't find the column, despite the quote function as:
data _null_;
a= "MD";
set GNC.GNC_CAUSES_NO_EDGE_BACK(obs=1);
call execute('proc fedsql sessref=EG_Session; select distinct id_remi from GNC.REMI_VOL_2008_2021_FINAL where id_class ='||quote(a)||'; quit;');
run;
Many thanks for considering my request.
Show a DIRECT call to fedsql that does work.
as in not generated by a data step, just the Proc fedsql submitted directly.
I am not familiar with all the stuff that gets involved with the connections. I am assuming the ID_class is a variable in the table GNC.REMI_VOL_2008_2021_FINAL. If not then I'm clueless at this point.
PROC FEDSQL is probably treating "MD" as a variable reference and is expecting you to use single quotes for literals. In PROC SQL you have to request this behavior but perhaps it is the default in PROC FEDSQL.
Tell the QUOTE() function to use single quotes.
quote(a,"'")
Thanks!
Working!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.