<?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 create a &amp;quot;dynamic&amp;quot; macro? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82804#M17865</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not sure what the issue here is.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Being able to provide the input parameters is why you would want to create a macro!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So if your analysis requires two lists of variables then give the user two macro parameters for them to specify the list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro analysis(data=,list1=,list2=);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc freq data=&amp;amp;data ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; tables (&amp;amp;list1)*(&amp;amp;list2) ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend analysis;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 22 May 2013 15:06:07 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2013-05-22T15:06:07Z</dc:date>
    <item>
      <title>How to create a "dynamic" macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82801#M17862</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Problem&lt;/P&gt;&lt;P&gt;I am performing repetitive queries on tables with two kinds of variables, lets call them samevar1-m, diffvar1-n.&lt;/P&gt;&lt;P&gt;I have no idea now to create a macro where I can enter the disired number of variables because once I compile it, the number cannot me changed. How can I make it more flexible?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any way to create a macro&lt;/P&gt;&lt;P&gt;%macro analysis (m, samevar1-m, n, diffvar1-n);&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;%mendo analysis (m, samevar1-m, n, diffvar1-n);&lt;/P&gt;&lt;P&gt;that uses the desired number of variables?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 May 2013 13:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82801#M17862</guid>
      <dc:creator>sfmeier</dc:creator>
      <dc:date>2013-05-22T13:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a "dynamic" macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82802#M17863</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could make it 100% dynamic by first querying the dictionnary view containing the column names. This way, you can count how many variables are named like 'samevar%' and then make a loop on these variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would do it as follow:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;sql&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; count(&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;distinct&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; name)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;into&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; :m&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; sashelp.vcolumn&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; upcase(libname) = &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 10pt;"&gt;'YOUR_LIBNAME'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; upcase(memname) = &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 10pt;"&gt;'YOUR_TABLENAME'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; upcase(name) like &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 10pt;"&gt;'SAMEVAR%'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;quit&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then you can use the macro-variable to loop on your variables "Samevar", with something as follow (or any other logic you want to apply):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;sql&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select Samevar1-Samevar%&lt;STRONG&gt;&lt;EM&gt;left&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;m.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :Samevar1-:Samevar%&lt;STRONG&gt;&lt;EM&gt;left&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;m.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from your_libname.your_tablename;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;quit&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;%macro&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;STRONG&gt;&lt;EM&gt;analysis&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;%do&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; i= &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;%to&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; %&lt;STRONG&gt;&lt;EM&gt;left&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;m);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;%put&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; Samevar&amp;amp;i = &amp;amp;&amp;amp;Samevar&amp;amp;i.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;%end&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;%mend&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; analysis;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;%analysis&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;I hope it helps.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Florent&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 May 2013 14:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82802#M17863</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2013-05-22T14:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a "dynamic" macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82803#M17864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't give any example of what you're doing but another approach is to provide a "base" for the variable and then suffixes;&lt;/P&gt;&lt;P&gt;If numeric it could be something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro process(base=samevar, startsuf=1, endsuf=10);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i = &amp;amp;startsuf %to &amp;amp;endsuf;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc freq data=dsn;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables &amp;amp;base.&amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have two variables with the same suffixes you would add anothe "base". if the suffixes weren't the same add suffix variables. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 May 2013 14:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82803#M17864</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-05-22T14:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a "dynamic" macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82804#M17865</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not sure what the issue here is.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Being able to provide the input parameters is why you would want to create a macro!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So if your analysis requires two lists of variables then give the user two macro parameters for them to specify the list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro analysis(data=,list1=,list2=);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc freq data=&amp;amp;data ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; tables (&amp;amp;list1)*(&amp;amp;list2) ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend analysis;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 May 2013 15:06:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82804#M17865</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-05-22T15:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a "dynamic" macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82805#M17866</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all for you replies.. However I meant something totally different. I have the following macro:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;*---------------------------------------------------------------------------------------------------+&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Auffinden von allen &amp;amp;Var1 mit verschiedenen Einträgen in der &amp;amp;Var2 in der Tabelle &amp;amp;Source&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; !!!&amp;nbsp; ALLE Inputvariablen müssen befüllt sein&amp;nbsp; !!!&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Die Variable &amp;amp;Resultvar wird in der Tabelle &amp;amp;Result zusätzlich ausgegeben&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;*---------------------------------------------------------------------------------------------------;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: navy; font-size: 10pt;"&gt;%Macro&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; doppel (Source, Var1, Var2, Resultvar, Result);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;/* Selektion aller vorhandenen, verschiedenen Paare von Var1 und Var2 */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;create table paare as &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct &amp;amp;Var1, &amp;amp;Var2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;from &amp;amp;Source;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;/* Selektion aller Var1 mit mehreren Var2 */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;create table doppel as &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct &amp;amp;Var1, count(*) as Anzahl&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from paare&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by &amp;amp;Var1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having Anzahl &amp;gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;1&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;/* Selektion "Var1", "Var2" und zusätzlicher "Resultvar"iable mit mehrfachen "Namen" */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;create table &amp;amp;Result as &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct &lt;/SPAN&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;r.&lt;/SPAN&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;amp;Var1, &lt;/SPAN&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;r.&lt;/SPAN&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;amp;Var2, &lt;/SPAN&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;r.&lt;/SPAN&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;amp;resultvar&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from &amp;amp;Source as r&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inner join doppel&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on &lt;/SPAN&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;doppel.&lt;/SPAN&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;amp;Var1=&lt;/SPAN&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;r.&lt;/SPAN&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;amp;Var1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;%Mend&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; doppel;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is working. But I want to be able to select up to n Var1-Var_n and m Var_n+1-Var_m+n in the macro call. So how do I do that?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 May 2013 13:57:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82805#M17866</guid>
      <dc:creator>sfmeier</dc:creator>
      <dc:date>2013-05-23T13:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a "dynamic" macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82806#M17867</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It looks like you are asking for a way to have a macro parse a variable list.&amp;nbsp; For example, instead of using Var1 as the value of the second parameter, use something like var45-var63.&amp;nbsp; If that's the case, here's the easy way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc contents data=&amp;amp;source (keep=&amp;amp;var1) noprint out=_contents_ (keep=name);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That will get you a data set with all the proper variable names in it.&amp;nbsp; It doesn't necessarily preserve the order, and Tom has published a neat way to use PROC TRANSPOSE to maintain the order.&amp;nbsp; But order doesn't seem to matter in your program, so let's stick to the simple way. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then create a set of macro variables as needed:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; select distinct(name) into : list1 from _contents_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; select distinct(name) into : list2 separated by ', ' from _contents_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; select distinct('r.' || name) into : list3 separated by ', ' from _contents_;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 May 2013 14:13:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82806#M17867</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-05-23T14:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a "dynamic" macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82807#M17868</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thx... I'd do that, but how can I perform a join on the variable list?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 May 2013 15:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82807#M17868</guid>
      <dc:creator>sfmeier</dc:creator>
      <dc:date>2013-05-23T15:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a "dynamic" macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82808#M17869</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's just a more complex SELECT statement in the final SQL.&amp;nbsp; You know the syntax you're looking for better than I, but something along these lines would be close:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select distinct('doppel.' || strip(name) || '=r.' || strip(name)) into : list4 separated by ', ' from _contents_;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The more I think about it, DISTINCT might be overkill here.&amp;nbsp; There variable names are already distinct ... just a side issue though.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 May 2013 15:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-quot-dynamic-quot-macro/m-p/82808#M17869</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-05-23T15:41:01Z</dc:date>
    </item>
  </channel>
</rss>

