<?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: Resolve macro at execution in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677775#M204505</link>
    <description>&lt;P&gt;One very simple way is to change FOLDER_CODE to a macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro folder_code;
  &amp;amp;location.&amp;amp;env\code
%mend;

%LET location=g:\sasdiv01\;
%LET env=prod;
%put %folder_code;

%let env=test;
%put %folder_code;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Aug 2020 12:26:25 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2020-08-19T12:26:25Z</dc:date>
    <item>
      <title>Resolve macro at execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677710#M204457</link>
      <description>&lt;P&gt;%LET location=g:\sasdiv01\;&lt;/P&gt;
&lt;P&gt;%LET env=prod;&lt;/P&gt;
&lt;P&gt;%LET folder_code=&amp;amp;location.&amp;amp;env.\code;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above works perfect, but now I only want to change the env at execution in my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want as a result is the following.&lt;/P&gt;
&lt;P&gt;%LET env=test;&lt;/P&gt;
&lt;P&gt;%LET folder_test=&amp;amp;folder_code;&lt;/P&gt;
&lt;P&gt;%PUT &amp;amp;=folder_test;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Current Result&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;folder_test=g:\sasdiv\prod\code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Desired Result&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;folder_test=g:\sasdiv\test\code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know it is not possible with the code i wrote above. Is there a way to do this a other way.&amp;nbsp; The reason I want to this is because all the references to folders and other stuff is in the 1 piece of code. We don't want any references to folders in the code directly (if we change a folder we only have to change it in that first piece of code).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2020 07:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677710#M204457</guid>
      <dc:creator>Richardvan_tHoff</dc:creator>
      <dc:date>2020-08-19T07:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve macro at execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677717#M204464</link>
      <description>&lt;P&gt;Yes you can, just by using a macro program, like next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro exec(env,folder_test=g:\sasdiv\test\code);
    %if &amp;amp;env=prod %then %do;
          %LET location=g:\sasdiv01\;
          %LET folder_code=&amp;amp;location.&amp;amp;env.\code;
    %end; %else
    %if &amp;amp;env=test %then %do;
          %LET folder_code=&amp;amp;folder_test;
          %PUT &amp;amp;=folder_test;
    %end;
     ..... enter your code here or %include it from a source folder ...
%mend exec;
%exec(&amp;lt;env&amp;gt;);  /* suppay the environment to run in */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2020 07:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677717#M204464</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-19T07:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve macro at execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677719#M204466</link>
      <description>&lt;P&gt;A macro variable does not know from which parts it was built, so it cannot update itself dynamically; you need to create the new variable like you created the old one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let location=g:\sasdiv01\;
%let env=prod;
%let folder_code=&amp;amp;location.&amp;amp;env.\code;

/* then, later: */

%let env=test;
%let folder_test=&amp;amp;location.&amp;amp;env.\code;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I played around a little trying to use indirect addressing of macro variables to achieve this, and while I suspect it may be possible (people with more macro-fu than me might find a way), I also suspect that it would create hard-to-maintain code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2020 07:42:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677719#M204466</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-19T07:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve macro at execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677721#M204468</link>
      <description>&lt;P&gt;Don't forget to use %global for variables you want to use later outside of the macro.&lt;/P&gt;
&lt;P&gt;Or create a function-style macro that resolves to code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let location=g:\sasdiv01\;

%macro set_path(env);
  &amp;amp;location.&amp;amp;env.\code
%mend;

%put %set_path(prod);
%put %set_path(test);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Aug 2020 07:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677721#M204468</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-19T07:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve macro at execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677735#M204479</link>
      <description>&lt;P&gt;Thank you all for your suggestions. For the problem I have it&amp;nbsp; will to work but not the way I want it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think it is not possible to change the value dynamically at execution time. I was looking for such a solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am working on a stored proces to transfer data en code from development to production. In that STP I have prompts to choose source and target (which are based on a column from a sas table in the metadata). Knowing that i solved the problem a other way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%LET g_sytem=acc;&lt;/P&gt;
&lt;P&gt;%LET g_system_folder_code=g:\sasdiv\program\&amp;amp;g_system.\code;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the stp I get the variables p_source en p_target;&lt;/P&gt;
&lt;P&gt;p_source=ont;&lt;/P&gt;
&lt;P&gt;p_target=prod;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%LET v_source_code_source =%SYSFUNC(TRANWRD(&amp;amp;g_system_folder_code.,\&amp;amp;g_system.\,\&amp;amp;p_source.\));&lt;/P&gt;
&lt;P&gt;%LET v_source_code_target&amp;nbsp; =%SYSFUNC(TRANWRD(&amp;amp;g_system_folder_code.,\&amp;amp;g_system.\,\&amp;amp;p_target.\));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This way i still use the standard available macro variable's.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2020 08:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677735#M204479</guid>
      <dc:creator>Richardvan_tHoff</dc:creator>
      <dc:date>2020-08-19T08:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve macro at execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677739#M204483</link>
      <description>&lt;P&gt;You can change any macro variable value according to a known condition, either in program or after a given trigger.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the code is part of a macro program you cat insert %IF &amp;lt;condition&amp;gt; and use %LET to assign a new value.&lt;/P&gt;
&lt;P&gt;If the code is part of a data step you can use a statement like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;if &amp;lt;condition&amp;gt; then call symput(&amp;lt;macro_name&amp;gt;, &amp;lt;macro_value&amp;gt;);&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having the code in a stored process, it needs of course to be changed/updated/adapted to the new requirements and restored.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2020 09:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677739#M204483</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-19T09:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Resolve macro at execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677775#M204505</link>
      <description>&lt;P&gt;One very simple way is to change FOLDER_CODE to a macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro folder_code;
  &amp;amp;location.&amp;amp;env\code
%mend;

%LET location=g:\sasdiv01\;
%LET env=prod;
%put %folder_code;

%let env=test;
%put %folder_code;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2020 12:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolve-macro-at-execution/m-p/677775#M204505</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-08-19T12:26:25Z</dc:date>
    </item>
  </channel>
</rss>

