Hi All.
I have a problem with that attached code.(see bottom of post)
I’m creating a dynamic WHERE statement based on the values I find in the macgen dataset.
This works fine in a ‘normal’ SAS data step, however when I attempt the same in my SQL DB2 pass thru it spits out the following –
DSNT408I SQLCODE = -206, ERROR: N7 IS NOT A COLUMN OF AN INSERTED TABLE, UPDATED TABLE, OR ANY TABLE IDENTIFIED IN A FROM CLAUSE, OR IS NOT A COLUMN OF THE TRIGGERING TABLE OF A TRIGGER
The macro seems to resolve to the following –
MPRINT(GENIN): "N7" , "Q2" , "Q3" , "Q4" , "Q5" , "Q6" , "Q7"
I have gathered that DB2 SQL treats text values in double quotes differently. Not sure what is going on exactly.
What I would like to do is some how adjust the text generated by the macro to only have single quotation marks round the values or even persuade the DB2 system to treat them as normal text.
Any help would be appreciated.
Thanks for reading.
CODE LISTING
data _null_;
set macgen;
call symput('mvar'||left(_n_),trim(account_type));
call symput('max',left(_n_));
run;
%macro genin;
%do i =1 %to &max;
"&&mvar&i"
%if &i ne &max %then %do;
,
%end;
%put input = "&&mvar&i";
%end;
%mend genin;
proc sql;
create table WORK.&bank._V_MST_CUS_ACCONH as
select *
from connection to db2
(
select customer_id, branch_no, account_no, account_open_date
from &bank..V_MST_CUS_ACCONH
where relation_type in ('O','OJ') and
account_type in (%genin)
order by branch_no, account_no, account_open_date, customer_id
);
quit;
I have a problem with that attached code.(see bottom of post)
I’m creating a dynamic WHERE statement based on the values I find in the macgen dataset.
This works fine in a ‘normal’ SAS data step, however when I attempt the same in my SQL DB2 pass thru it spits out the following –
DSNT408I SQLCODE = -206, ERROR: N7 IS NOT A COLUMN OF AN INSERTED TABLE, UPDATED TABLE, OR ANY TABLE IDENTIFIED IN A FROM CLAUSE, OR IS NOT A COLUMN OF THE TRIGGERING TABLE OF A TRIGGER
The macro seems to resolve to the following –
MPRINT(GENIN): "N7" , "Q2" , "Q3" , "Q4" , "Q5" , "Q6" , "Q7"
I have gathered that DB2 SQL treats text values in double quotes differently. Not sure what is going on exactly.
What I would like to do is some how adjust the text generated by the macro to only have single quotation marks round the values or even persuade the DB2 system to treat them as normal text.
Any help would be appreciated.
Thanks for reading.
CODE LISTING
data _null_;
set macgen;
call symput('mvar'||left(_n_),trim(account_type));
call symput('max',left(_n_));
run;
%macro genin;
%do i =1 %to &max;
"&&mvar&i"
%if &i ne &max %then %do;
,
%end;
%put input = "&&mvar&i";
%end;
%mend genin;
proc sql;
create table WORK.&bank._V_MST_CUS_ACCONH as
select *
from connection to db2
(
select customer_id, branch_no, account_no, account_open_date
from &bank..V_MST_CUS_ACCONH
where relation_type in ('O','OJ') and
account_type in (%genin)
order by branch_no, account_no, account_open_date, customer_id
);
quit;