<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to use a SAS macro variable in a SQL pass through connection with snowflake database in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-SAS-macro-variable-in-a-SQL-pass-through-connection/m-p/979138#M46283</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;LI-CODE lang="sas"&gt;%macro test(value);
%LET cn_SNOW = database=&amp;amp;databaseName.
SQL_FUNCTIONS=ALL
SERVER="&amp;amp;serverName."
SCHEMA=&amp;amp;schema.
AUTHDOMAIN=&amp;amp;authdomain.;

/************************* Defining some Time travel macro variables    ******************/
%let current_day=%sysfunc(today(), yymmdd10.);
%let now = %sysevalf(%sysfunc(time()) + 120);
%let current_time=%sysfunc(putn(&amp;amp;now., time.));
%put &amp;amp;=current_time &amp;amp;=current_day;

%let my_date_formatted = %sysfunc(intnx(day, %sysfunc(today()), -7), yymmdd10.);
%put &amp;amp;=my_date_formatted;

%let timestamp=at(timestamp=&amp;gt; %str(%')&amp;amp;my_date_formatted  &amp;amp;current_time%str(%')::timestamp_ltz);
%put &amp;amp;=timestamp;

proc sql;
connect to snow(&amp;amp;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 &amp;amp;timestamp. as contractVer 
               join CONTRACTPL_DM.LKP_PROGRAM &amp;amp;timestamp. 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 %str(%')&amp;amp;value.%str(%') = 'be' then '010'
               when %str(%')&amp;amp;value.%str(%') = 'gc' then '001'
               else 'Other'
               End as newvar


     from TEMPTBL
);
             
        disconnect from snow;
quit;
%mend test;
%test(be);&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 19 Nov 2025 16:22:33 GMT</pubDate>
    <dc:creator>alepage</dc:creator>
    <dc:date>2025-11-19T16:22:33Z</dc:date>
    <item>
      <title>how to use a SAS macro variable in a SQL pass through connection with snowflake database</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-SAS-macro-variable-in-a-SQL-pass-through-connection/m-p/979127#M46278</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below, you will see an example of a SQL pass through connection to a snowflake database and it works very well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(value);
%LET cn_SNOW = database=&amp;amp;databaseName.
SQL_FUNCTIONS=ALL
SERVER="&amp;amp;serverName."
SCHEMA=&amp;amp;schema.
AUTHDOMAIN=&amp;amp;authdomain.;

/************************* Defining some Time travel macro variables    ******************/
%let current_day=%sysfunc(today(), yymmdd10.);
%let now = %sysevalf(%sysfunc(time()) + 120);
%let current_time=%sysfunc(putn(&amp;amp;now., time.));
%put &amp;amp;=current_time &amp;amp;=current_day;

%let my_date_formatted = %sysfunc(intnx(day, %sysfunc(today()), -7), yymmdd10.);
%put &amp;amp;=my_date_formatted;

%let timestamp=at(timestamp=&amp;gt; %str(%')&amp;amp;my_date_formatted  &amp;amp;current_time%str(%')::timestamp_ltz);
%put &amp;amp;=timestamp;

proc sql;
connect to snow(&amp;amp;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 &amp;amp;timestamp. as contractVer 
               join CONTRACTPL_DM.LKP_PROGRAM &amp;amp;timestamp. 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);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if I want to use a case statement, how do we pass the &amp;amp;value. in a Snowflake SQL script?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro test(value);
%LET cn_SNOW = database=&amp;amp;databaseName.
SQL_FUNCTIONS=ALL
SERVER="&amp;amp;serverName."
SCHEMA=&amp;amp;schema.
AUTHDOMAIN=&amp;amp;authdomain.;

/************************* Defining some Time travel macro variables    ******************/
%let current_day=%sysfunc(today(), yymmdd10.);
%let now = %sysevalf(%sysfunc(time()) + 120);
%let current_time=%sysfunc(putn(&amp;amp;now., time.));
%put &amp;amp;=current_time &amp;amp;=current_day;

%let my_date_formatted = %sysfunc(intnx(day, %sysfunc(today()), -7), yymmdd10.);
%put &amp;amp;=my_date_formatted;

%let timestamp=at(timestamp=&amp;gt; %str(%')&amp;amp;my_date_formatted  &amp;amp;current_time%str(%')::timestamp_ltz);
%put &amp;amp;=timestamp;

proc sql;
connect to snow(&amp;amp;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 &amp;amp;timestamp. as contractVer 
               join CONTRACTPL_DM.LKP_PROGRAM &amp;amp;timestamp. 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 &amp;amp;value. = 'be' then '010'
               when &amp;amp;value. = 'gc' then '001'
               End as newvar


     from TEMPTBL
);
             
        disconnect from snow;
quit;
%mend test;
%test(be);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I did some test and I know that the &amp;amp;value. is throwing an error.&lt;/P&gt;
&lt;P&gt;How to solve that issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2025 15:17:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-SAS-macro-variable-in-a-SQL-pass-through-connection/m-p/979127#M46278</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-11-19T15:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a SAS macro variable in a SQL pass through connection with snowflake database</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-SAS-macro-variable-in-a-SQL-pass-through-connection/m-p/979130#M46281</link>
      <description>&lt;P&gt;Whenever SAS encounters a macro variable in code, it replaces the macro variable with its actual value, and then runs the code with these replacements made. So, for this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;     select * ,
               case
               when &amp;amp;value. = 'be' then '010'
               when &amp;amp;value. = 'gc' then '001'
               End as newvar&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the code that is actually executed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;     
     select * ,
               case
               when be = 'be' then '010'
               when be = 'gc' then '001'
               End as newvar&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SQL thinks BE is the name of a variable in the table. (Do you understand why SAS thinks BE is the name of a variable in the table?) So this code only makes sense if the table that SQL is working on (TEMPTBL) has a variable named BE. Does it?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;A much better approach to create programs with macro variables is to get the code to work without macro variables first, and then substitute the macro variables into the code. But you haven't done that, and so it is highly recommended.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, please tell us, what is the code you want to have executed here, without macro variables.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Finally, when you are getting errors in the log, please show us (&lt;STRONG&gt;ALWAYS&lt;/STRONG&gt;) the relevant parts of the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2025 16:05:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-SAS-macro-variable-in-a-SQL-pass-through-connection/m-p/979130#M46281</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-11-19T16:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a SAS macro variable in a SQL pass through connection with snowflake database</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-SAS-macro-variable-in-a-SQL-pass-through-connection/m-p/979138#M46283</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;LI-CODE lang="sas"&gt;%macro test(value);
%LET cn_SNOW = database=&amp;amp;databaseName.
SQL_FUNCTIONS=ALL
SERVER="&amp;amp;serverName."
SCHEMA=&amp;amp;schema.
AUTHDOMAIN=&amp;amp;authdomain.;

/************************* Defining some Time travel macro variables    ******************/
%let current_day=%sysfunc(today(), yymmdd10.);
%let now = %sysevalf(%sysfunc(time()) + 120);
%let current_time=%sysfunc(putn(&amp;amp;now., time.));
%put &amp;amp;=current_time &amp;amp;=current_day;

%let my_date_formatted = %sysfunc(intnx(day, %sysfunc(today()), -7), yymmdd10.);
%put &amp;amp;=my_date_formatted;

%let timestamp=at(timestamp=&amp;gt; %str(%')&amp;amp;my_date_formatted  &amp;amp;current_time%str(%')::timestamp_ltz);
%put &amp;amp;=timestamp;

proc sql;
connect to snow(&amp;amp;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 &amp;amp;timestamp. as contractVer 
               join CONTRACTPL_DM.LKP_PROGRAM &amp;amp;timestamp. 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 %str(%')&amp;amp;value.%str(%') = 'be' then '010'
               when %str(%')&amp;amp;value.%str(%') = 'gc' then '001'
               else 'Other'
               End as newvar


     from TEMPTBL
);
             
        disconnect from snow;
quit;
%mend test;
%test(be);&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 19 Nov 2025 16:22:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-SAS-macro-variable-in-a-SQL-pass-through-connection/m-p/979138#M46283</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-11-19T16:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a SAS macro variable in a SQL pass through connection with snowflake database</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-SAS-macro-variable-in-a-SQL-pass-through-connection/m-p/979140#M46285</link>
      <description>&lt;P&gt;This is even easier than your solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;     select * ,
               case
               when "&amp;amp;value" = 'be' then '010'
               when "&amp;amp;value" = 'gc' then '001'
               else 'Other'
               end as newvar&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Nov 2025 16:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-SAS-macro-variable-in-a-SQL-pass-through-connection/m-p/979140#M46285</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-11-19T16:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a SAS macro variable in a SQL pass through connection with snowflake database</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-SAS-macro-variable-in-a-SQL-pass-through-connection/m-p/979145#M46286</link>
      <description>No! The SQL query in Snowflake does not take "&amp;amp;Value"</description>
      <pubDate>Wed, 19 Nov 2025 18:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-SAS-macro-variable-in-a-SQL-pass-through-connection/m-p/979145#M46286</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-11-19T18:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a SAS macro variable in a SQL pass through connection with snowflake database</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-SAS-macro-variable-in-a-SQL-pass-through-connection/m-p/979149#M46287</link>
      <description>&lt;P&gt;So you basically want to set a costant value. Let the macro processor do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;     select * ,
%if &amp;amp;value. = be %then '010';
%else %if &amp;amp;value. = gc %then '001';
%else 'xxx';
               as newvar&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Nov 2025 19:41:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-a-SAS-macro-variable-in-a-SQL-pass-through-connection/m-p/979149#M46287</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-11-19T19:41:08Z</dc:date>
    </item>
  </channel>
</rss>

