<?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: Determine the value of macro variable dynamically in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747369#M234557</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Thank you. Your code is working fine as excepted. Can we also handle the same scenario using parsing function?&lt;/P&gt;</description>
    <pubDate>Fri, 11 Jun 2021 15:10:00 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2021-06-11T15:10:00Z</dc:date>
    <item>
      <title>Determine the value of macro variable dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747256#M234505</link>
      <description>&lt;P&gt;I've the code as follows and it is working fine even if the value of the macro variables are swapped between them. In the below code even if you change the value between _OUTPUT1 and _OUTPUT0 it will display the right results. In this case the value IFRSITSS.META_DATA is fixed and it can be assigned either to _OUTPUT0 or _OUTPUT1. Other value IFRSITSS.INSURANCE varies.In either case, following code yields right results as given below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the customer want to introduce two more&amp;amp;nbsp;macro varibles&amp;amp;nbsp;like %let _OUTPUT2=IFRSITSS.AUDIT_TRAIL;&lt;BR /&gt;and this value is fixed and it will never change. But this value can be assigned to any of the macro variables like _OUTPUT0 or _OUTPUT1 or _OUTPUT2. Other macro variable is&lt;BR /&gt;%let sql_audit_itss=AUDIT_TRAIL; and this value and the macro variable will never change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case how can I tweak the below %if clause and createtwo more macro variables like audit_table and audit_table_sql.&lt;/P&gt;
&lt;P&gt;Hint is %let sql_audit_itss=AUDIT_TRAIL; and %let sql_meta_itss=META_DATA; will never change and the values IFRSITSS.META_DATA and IFRSITSS.AUDIT_TRAIL is fixed and it will be assigned to any of the macro variables _OUTPUT0 or _OUTPUT1 or _OUTPUT2. Any help to tackle the Scenario using macro? Any ways to do this with other than %if.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired results are also given below. Program which I've is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let _OUTPUT1 = IFRSITSS.META_DATA;
%let _OUTPUT0 = IFRSITSS.INSURANCE;
%let sql_meta_itss=META_DATA;

data _null_;
%if %substr(_OUTPUT0.,10,%length(_OUTPUT0.))= sql_meta_itss. %then %do;
%let trans_table_sql=%substr(_OUTPUT1.,10,%length(_OUTPUT1.));
%let trans_table=_OUTPUT1.;
%let Meta_table_sql=%substr(_OUTPUT0.,10,%length(_OUTPUT0.));
%let Meta_table=_OUTPUT0.;
%end;

%if %substr(;_OUTPUT0.,10,%length(_OUTPUT0.)) NE sql_meta_itss. %then %do;
%let trans_table_sql=%substr(_OUTPUT0.,10,%length(_OUTPUT0.));
%let trans_table=&amp;amp;amp;_OUTPUT0.;
%let Meta_table_sql=%substr(_OUTPUT1.,10,%length(_OUTPUT1.));
%let Meta_table=_OUTPUT1.;
%end;
run;

%put #### Trans_table_sql value is trans_table_sql.;
%put #### Trans_table value is trans_input.;
%put #### Meta_table_sql value is Meta_table_sql.
%put #### Meta_table value is Meta_table.;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Trans_table value is IFRSITSS.INSURANCE&lt;BR /&gt;Trans_table_sql value is INSURANCE&lt;BR /&gt;Meta_table value is IFRSITSS.META_DATA&lt;BR /&gt;Meta_table_sql value is META_DATA&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired results for the Scenario which I explained above is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Trans_table value is IFRSITSS.INSURANCE&lt;BR /&gt;Trans_table_sql value is INSURANCE&lt;BR /&gt;Meta_table value is IFRSITSS.META_DATA&lt;BR /&gt;Meta_table_sql value is META_DATA&lt;BR /&gt;Audit_table value is IFRSITSS.AUDIT_TRAIL&lt;BR /&gt;Audit_table_sql value is AUDIT_TRAIL&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 04:46:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747256#M234505</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-06-11T04:46:42Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the value of macro variable dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747257#M234506</link>
      <description>&lt;P&gt;Why did you include these statements?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are going to insert SAS statement that will force a new SAS step why not just write the logic using data step code instead of macro code?&amp;nbsp; That is normally a LOT easier to write, read and debug than macro code.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 03:28:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747257#M234506</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-11T03:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the value of macro variable dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747259#M234507</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;In real life it's very big macro code which includes other steps. I just want to update the logic only in the steps which I posted. I'm fine to receive help in data step:) Later I will adjust it to macro.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 03:41:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747259#M234507</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-06-11T03:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the value of macro variable dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747262#M234509</link>
      <description>&lt;P&gt;Did you accidently type your SAS code into and HTML file?&lt;/P&gt;
&lt;P&gt;Why does it have &amp;amp;amp; in it?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 04:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747262#M234509</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-11T04:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the value of macro variable dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747269#M234511</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Corrected now&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 04:47:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747269#M234511</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-06-11T04:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the value of macro variable dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747273#M234514</link>
      <description>&lt;P&gt;I cannot figure out what you are asking.&lt;/P&gt;
&lt;P&gt;Please explain what is the input.&amp;nbsp; What is the desired output. What is are the rules for converting the input to the output?&lt;/P&gt;
&lt;P&gt;Is there some pattern of text that appears in the values of OUTPUT0 (or OUTPUT1) that helps you figure out whether to use it as the META or the TRANS target macro variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note we probably do not need to worry about creating the xxx_SQL macro variable of those look like they are simply the last word of the corresponding xxx macro variable.&amp;nbsp; For example once you have set TRANS_TABLE you can make TRANS_TABLE_SQL from it very easily.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let trans_table_sql=%scan(&amp;amp;trans_table,-1,.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 05:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747273#M234514</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-11T05:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the value of macro variable dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747274#M234515</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;This is the rule as I mentioned in my post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've the code as follows and it is working fine even if the value of the macro variables are swapped between them. In the below code even if you change the value between _OUTPUT1 and _OUTPUT0 it will display the right results. In this case the value IFRSITSS.META_DATA is fixed and it can be assigned either to _OUTPUT0 or _OUTPUT1. Other value IFRSITSS.INSURANCE varies.In either case, following code yields right results as given below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the customer want to introduce two more&amp;amp;nbsp;macro varibles&amp;amp;nbsp;like %let _OUTPUT2=IFRSITSS.AUDIT_TRAIL;&lt;BR /&gt;and this value is fixed and it will never change. But this value can be assigned to any of the macro variables like _OUTPUT0 or _OUTPUT1 or _OUTPUT2. Other macro variable is&lt;BR /&gt;%let sql_audit_itss=AUDIT_TRAIL; and this value and the macro variable will never change.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 05:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747274#M234515</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-06-11T05:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the value of macro variable dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747276#M234517</link>
      <description>&lt;P&gt;If the values are fixed then just hard code them. To find the odd man out just concatenate all three inputs and remove the "fixed" values. What's left is the third value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%* Set example input values ;
%let _output0=IFRSITSS.META_DATA;
%let _output1=IFRSITSS.INSURANCE;
%let _output2=IFRSITSS.AUDIT_TRAIL;

%* Set the FIXED values ;
%let meta_table=IFRSITSS.META_DATA;
%let audit_table=IFRSITSS.AUDIT_TRAIL;

%* Calculate TRANS_TABLE by removing the FIXED table names from the list of all three ;
%let trans_table=&amp;amp;_output0 &amp;amp;_output1 &amp;amp;_output2;
%let trans_table=%sysfunc(tranwrd(&amp;amp;trans_table,&amp;amp;meta_table,));
%let trans_table=%sysfunc(tranwrd(&amp;amp;trans_table,&amp;amp;audit_table,));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;300  %* Show the results ;
301  %put &amp;amp;=trans_table;
TRANS_TABLE=IFRSITSS.INSURANCE&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 05:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747276#M234517</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-11T05:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the value of macro variable dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747369#M234557</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Thank you. Your code is working fine as excepted. Can we also handle the same scenario using parsing function?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 15:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-value-of-macro-variable-dynamically/m-p/747369#M234557</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-06-11T15:10:00Z</dc:date>
    </item>
  </channel>
</rss>

