<?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: proc sql from tablex based on the value of a macro variable in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-from-tablex-based-on-the-value-of-a-macro-variable/m-p/420539#M27042</link>
    <description>&lt;P&gt;Why have a parameter which tells the code which library to look at?&amp;nbsp; That just seems like an unnecessary step.&amp;nbsp; Code you program to look&amp;nbsp; at a library, the only switch needs to be where you assign the library:&lt;/P&gt;
&lt;PRE&gt;libname curr "%sysfunc(pathname(symu))";

/* Replace with this for prod
libname curr "%sysfunc(pathname(i2symu))";
*/

proc sql;
  ...
  from CURR....;
quit;&lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Dec 2017 17:38:19 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-12-12T17:38:19Z</dc:date>
    <item>
      <title>proc sql from tablex based on the value of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-from-tablex-based-on-the-value-of-a-macro-variable/m-p/420522#M27037</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to make create a table using a proc sql but selecting different library based on the type of environment (DEV for development or PROD for production) .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For exemple, if TypeEnv&amp;nbsp; eq DEV , I would like to select the symy library and if TypeEnv eq PROD, I would like to select the 12symu library&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried this code and it is not working&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let typeEnv=DEV;&lt;BR /&gt;*%let typeEnv=PROD;&lt;/P&gt;&lt;P&gt;%macro Transfert;&lt;BR /&gt;/*tranferts par agents ATO (Agents au Traitement des Opportunités);*/&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table transfert&lt;BR /&gt;as select table1.quand, table1.cdnname, table1.callsanswered as transferts, table1.callsoffered, table1.callsabandoned,&lt;BR /&gt;table1.callsterminated, table2.sannee, table2.smois, table2.trimestre, table2.semaine&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%if typeEnv eq DEV %then&lt;BR /&gt;%do;&lt;BR /&gt;FROM symu.icdnstat as table1 left join commun.dates as table2&lt;BR /&gt;ON table1.quand = table2.date;&lt;BR /&gt;%end;&lt;BR /&gt;%else&lt;BR /&gt;%do;&lt;BR /&gt;FROM l2symu.icdnstat as table1 left join commun.dates as table2&lt;BR /&gt;ON table1.quand = table2.date;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;QUIT;&lt;BR /&gt;%mend Transfert;&lt;BR /&gt;%Transfert;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does any one have already found a solution for this situation?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 17:00:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-from-tablex-based-on-the-value-of-a-macro-variable/m-p/420522#M27037</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2017-12-12T17:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql from tablex based on the value of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-from-tablex-based-on-the-value-of-a-macro-variable/m-p/420524#M27039</link>
      <description>&lt;P&gt;What about creating a macro variable with the correct library reference and using that in the join instead of the conditional logic on the join?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Untested but should give you the idea:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Transfert(env=);
/*tranferts par agents ATO (Agents au Traitement des Opportunités);*/

data _null_;
    if "&amp;amp;env"="PROD" then call symputx('mylib', 'symu', 'l');
    else if "&amp;amp;env" = "DEV" then call symputx('mylib', 'l2symu', 'l');
run;

proc sql;
    create table transfert
    as select table1.quand, table1.cdnname, table1.callsanswered as transferts, table1.callsoffered, table1.callsabandoned,
    table1.callsterminated, table2.sannee, table2.smois, table2.trimestre, table2.semaine

    FROM &amp;amp;mylib..icdnstat as table1 
    left join commun.dates as table2
    ON table1.quand = table2.date;

QUIT;

%mend Transfert;

%Transfert(DEV);
%Transfert(PROD);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Dec 2017 17:05:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-from-tablex-based-on-the-value-of-a-macro-variable/m-p/420524#M27039</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-12T17:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql from tablex based on the value of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-from-tablex-based-on-the-value-of-a-macro-variable/m-p/420528#M27041</link>
      <description>&lt;P&gt;Have you tried properly referencing your macro variable?&amp;nbsp; This is never going to match:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%if typeEnv eq DEV %then&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%do;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead, the comparison should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%if &amp;amp;typeEnv eq DEV %then&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%do;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2017 17:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-from-tablex-based-on-the-value-of-a-macro-variable/m-p/420528#M27041</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-12T17:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql from tablex based on the value of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-from-tablex-based-on-the-value-of-a-macro-variable/m-p/420539#M27042</link>
      <description>&lt;P&gt;Why have a parameter which tells the code which library to look at?&amp;nbsp; That just seems like an unnecessary step.&amp;nbsp; Code you program to look&amp;nbsp; at a library, the only switch needs to be where you assign the library:&lt;/P&gt;
&lt;PRE&gt;libname curr "%sysfunc(pathname(symu))";

/* Replace with this for prod
libname curr "%sysfunc(pathname(i2symu))";
*/

proc sql;
  ...
  from CURR....;
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Dec 2017 17:38:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/proc-sql-from-tablex-based-on-the-value-of-a-macro-variable/m-p/420539#M27042</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-12T17:38:19Z</dc:date>
    </item>
  </channel>
</rss>

