<?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: Dynamic Macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macros/m-p/733820#M228666</link>
    <description>Thank you</description>
    <pubDate>Wed, 14 Apr 2021 16:28:05 GMT</pubDate>
    <dc:creator>vnreddy</dc:creator>
    <dc:date>2021-04-14T16:28:05Z</dc:date>
    <item>
      <title>Dynamic Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macros/m-p/733813#M228659</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could someone help me how can i use the required_tables macro in where statement.&lt;/P&gt;
&lt;P&gt;At present i have used it manually, but in future required tables might changes so i want to use the macro in where statement.&lt;/P&gt;
&lt;P&gt;Basically i am trying to see two datasets info.&lt;/P&gt;
&lt;PRE&gt;%let required_tables=
	Accoun_tbl Payments_tbl
;
libname lib "/sas/UAT/Data/";

PROC SQL;
	create table temp as
		SELECT	memname,
			nobs,
			nvar,
			filesize
		FROM DICTIONARY.TABLES
			WHERE MEMTYPE = 'DATA' and memname IN ('Accoun_tbl' , 'Payments_tbl')
				AND LIBNAME = "LIB";
QUIT;&lt;/PRE&gt;
&lt;P&gt;Could someone help me with about query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;vnreddy&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 16:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macros/m-p/733813#M228659</guid>
      <dc:creator>vnreddy</dc:creator>
      <dc:date>2021-04-14T16:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macros/m-p/733815#M228661</link>
      <description>&lt;P&gt;I think this question has come up before.&amp;nbsp; There are some macro "functions" that users have created to convert a delimited list of values into a quoted list of values.&amp;nbsp; For example:&amp;nbsp; &lt;A href="https://github.com/sasutils/macros/blob/master/qlist.sas" target="_self"&gt;%qlist()&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; memname IN %qlist(&amp;amp;required_tables)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you don't really need it for this.&amp;nbsp; You could use INDEXW() or FINDW() function instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;indexw("&amp;amp;required_tables",trim(memname),' ')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS:&amp;nbsp; &lt;FONT face="courier new,courier"&gt;%qlist&lt;/FONT&gt; is a macro.&amp;nbsp; &lt;FONT face="courier new,courier"&gt;&amp;amp;required_tables&lt;/FONT&gt; is a macro variable or if you want a one word name you can call it a symbol.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 16:19:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macros/m-p/733815#M228661</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-14T16:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macros/m-p/733817#M228663</link>
      <description>&lt;P&gt;Terminology is important. You're working with macro variables here - not a macro.&lt;/P&gt;
&lt;P&gt;Macro variables can be treated initially as simple find and replace.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your code will become:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let &lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt;required_tables&lt;/STRONG&gt;&lt;/FONT&gt;= &lt;FONT size="4" color="#FF9900"&gt;&lt;STRONG&gt;Accoun_tbl Payments_tbl&lt;/STRONG&gt;&lt;/FONT&gt;;
libname lib "/sas/UAT/Data/";

PROC SQL;
	create table temp as
		SELECT	memname,
			nobs,
			nvar,
			filesize
		FROM DICTIONARY.TABLES
			WHERE MEMTYPE = 'DATA' and memname IN (&lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt;&amp;amp;required_tables&lt;/STRONG&gt;&lt;/FONT&gt;)
				AND LIBNAME = "LIB";
QUIT;&lt;/PRE&gt;
&lt;P&gt;But that will generate a line as follows - replacing the macro variable with your value. This is not valid SAS code. It needs the quotes at minimum, the comma ideally.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;WHERE MEMTYPE = 'DATA' and memname IN (Accoun_tbl Payments_tbl)&lt;/PRE&gt;
&lt;P&gt;Can you create the macro variable with the quotes and comma? Then what happens?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let required_tables= 'Accoun_tbl' , 'Payments_tbl';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does that work for you as a solution?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Tutorial on converting a working program to a macro&lt;BR /&gt;&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Examples of common macro usage&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 16:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macros/m-p/733817#M228663</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-14T16:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macros/m-p/733818#M228664</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301412"&gt;@vnreddy&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you only find uppercase member names in DICTIONARY.TABLES. So, you can use this condition:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;memname IN (&lt;STRONG&gt;"%sysfunc(tranwrd(%upcase(&amp;amp;required_tables),%str( )," "))"&lt;/STRONG&gt;)&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;(assuming that the table names don't contain blanks).&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 16:37:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macros/m-p/733818#M228664</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-04-14T16:37:22Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macros/m-p/733819#M228665</link>
      <description>Thank you it worked.</description>
      <pubDate>Wed, 14 Apr 2021 16:24:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macros/m-p/733819#M228665</guid>
      <dc:creator>vnreddy</dc:creator>
      <dc:date>2021-04-14T16:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macros/m-p/733820#M228666</link>
      <description>Thank you</description>
      <pubDate>Wed, 14 Apr 2021 16:28:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Macros/m-p/733820#M228666</guid>
      <dc:creator>vnreddy</dc:creator>
      <dc:date>2021-04-14T16:28:05Z</dc:date>
    </item>
  </channel>
</rss>

