Hello,
Below, you will see an example of a SQL pass through connection to a snowflake database and it works very well.
%macro test(value);
%LET cn_SNOW = database=&databaseName.
SQL_FUNCTIONS=ALL
SERVER="&serverName."
SCHEMA=&schema.
AUTHDOMAIN=&authdomain.;
/************************* Defining some Time travel macro variables ******************/
%let current_day=%sysfunc(today(), yymmdd10.);
%let now = %sysevalf(%sysfunc(time()) + 120);
%let current_time=%sysfunc(putn(&now., time.));
%put &=current_time &=current_day;
%let my_date_formatted = %sysfunc(intnx(day, %sysfunc(today()), -7), yymmdd10.);
%put &=my_date_formatted;
%let timestamp=at(timestamp=> %str(%')&my_date_formatted ¤t_time%str(%')::timestamp_ltz);
%put &=timestamp;
proc sql;
connect to snow(&cn_SNOW.);
CREATE TABLE TEMP AS
select * from connection to snow
(
WITH TEMPTBL as
(
select LKPPGM.*,
'O' as Affinity_Ind
from CONTRACTPL_DM.DIM_PL_CNTRCT_VER ×tamp. as contractVer
join CONTRACTPL_DM.LKP_PROGRAM ×tamp. as LKPPGM
ON LKPPGM.DIM_PL_CNTRCT_VER_KEY = contractVer.DIM_PL_CNTRCT_VER_KEY
where LKPPGM.PROG_NM_CD='AFP' and LKPPGM.PROG_CAT_CD = 'INSBUSTRM'
order by contractVer.DIM_PL_CNTRCT_VER_KEY
)
select *
from TEMPTBL
);
disconnect from snow;
quit;
%mend test;
%test(be);
But if I want to use a case statement, how do we pass the &value. in a Snowflake SQL script?
%macro test(value);
%LET cn_SNOW = database=&databaseName.
SQL_FUNCTIONS=ALL
SERVER="&serverName."
SCHEMA=&schema.
AUTHDOMAIN=&authdomain.;
/************************* Defining some Time travel macro variables ******************/
%let current_day=%sysfunc(today(), yymmdd10.);
%let now = %sysevalf(%sysfunc(time()) + 120);
%let current_time=%sysfunc(putn(&now., time.));
%put &=current_time &=current_day;
%let my_date_formatted = %sysfunc(intnx(day, %sysfunc(today()), -7), yymmdd10.);
%put &=my_date_formatted;
%let timestamp=at(timestamp=> %str(%')&my_date_formatted ¤t_time%str(%')::timestamp_ltz);
%put &=timestamp;
proc sql;
connect to snow(&cn_SNOW.);
CREATE TABLE TEMP AS
select * from connection to snow
(
WITH TEMPTBL as
(
select LKPPGM.*,
'O' as Affinity_Ind
from CONTRACTPL_DM.DIM_PL_CNTRCT_VER ×tamp. as contractVer
join CONTRACTPL_DM.LKP_PROGRAM ×tamp. as LKPPGM
ON LKPPGM.DIM_PL_CNTRCT_VER_KEY = contractVer.DIM_PL_CNTRCT_VER_KEY
where LKPPGM.PROG_NM_CD='AFP' and LKPPGM.PROG_CAT_CD = 'INSBUSTRM'
order by contractVer.DIM_PL_CNTRCT_VER_KEY
)
select * ,
case
when &value. = 'be' then '010'
when &value. = 'gc' then '001'
End as newvar
from TEMPTBL
);
disconnect from snow;
quit;
%mend test;
%test(be);
I did some test and I know that the &value. is throwing an error.
How to solve that issue.
... View more