<?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: Creating macro variables lists based on the value of another variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro-variables-lists-based-on-the-value-of-another/m-p/154911#M298709</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks to both of you for very helpful answers that worked great. Much appreciated!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 24 Mar 2014 20:45:13 GMT</pubDate>
    <dc:creator>sgnolek</dc:creator>
    <dc:date>2014-03-24T20:45:13Z</dc:date>
    <item>
      <title>Creating macro variables lists based on the value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro-variables-lists-based-on-the-value-of-another/m-p/154908#M298706</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I want to be able to dynamically define a series of macro variables based on the value of another variable. The easiest example to describe this would be... say I have a list of reporting variables (A_rpt, B_rpt, C_rpt...) and I know what pages I want them to appear on when I create some ODS output. So imagine I have a data set like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;RPT_Variable&amp;nbsp;&amp;nbsp;&amp;nbsp; Page&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;A_rpt&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; 1&lt;/P&gt;&lt;P&gt;B_rpt&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; 1&lt;/P&gt;&lt;P&gt;C_rpt&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; 1&lt;/P&gt;&lt;P&gt;D_rpt&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; 2&lt;/P&gt;&lt;P&gt;E_rpt&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; 3&lt;/P&gt;&lt;P&gt;F_rpt&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; 3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to create three different macro variable lists that would contain the following&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;List1 = A_rpt B_rpt C_rpt&lt;/P&gt;&lt;P&gt;List2 = D_rpt&lt;/P&gt;&lt;P&gt;List3 = E_rpt F_rpt&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can find lots of examples of how to put a &lt;STRONG&gt;single&lt;/STRONG&gt; list into a macro variable (either using %let, or SQL), or how to create a &lt;STRONG&gt;series&lt;/STRONG&gt; of macro variables using SQL (shown below), but any hints how to do something that is somewhere in between, either by modifying the code below or taken a different approach? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any help you can provide&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro rptlist;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select distinct rpt_variable into:rptvar1-:rptvar999 from set_my_page;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select page into:page1-:page999 from set_my_page;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do i = 1 %to&amp;amp;sqlobs;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;&amp;amp;rpt_var&amp;amp;i &amp;amp;&amp;amp;page&amp;amp;i;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%varlist;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2014 19:33:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro-variables-lists-based-on-the-value-of-another/m-p/154908#M298706</guid>
      <dc:creator>sgnolek</dc:creator>
      <dc:date>2014-03-24T19:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro variables lists based on the value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro-variables-lists-based-on-the-value-of-another/m-p/154909#M298707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;input&amp;nbsp; RPT_Variable $ page;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;A_rpt 1&lt;/P&gt;&lt;P&gt;B_rpt 1&lt;/P&gt;&lt;P&gt;C_rpt 1&lt;/P&gt;&lt;P&gt;D_rpt 2&lt;/P&gt;&lt;P&gt;E_rpt 3&lt;/P&gt;&lt;P&gt;F_rpt 3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select distinct page into :pages separated by '|' from test;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;PAGES;&lt;/P&gt;&lt;P&gt;%do i= 1 %to %sysfunc(countw(&amp;amp;pages,'|'));&lt;/P&gt;&lt;P&gt;%let list=%scan(&amp;amp;pages,&amp;amp;i,'|');&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select RPT_Variable into :list_&amp;amp;list separated by ' ' from test&lt;/P&gt;&lt;P&gt;where page=&amp;amp;list;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%put&amp;nbsp; list_&amp;amp;list--&amp;gt;&amp;amp;&amp;amp;list_&amp;amp;list;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;output:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;list_1--&amp;gt;A_rpt B_rpt C_rpt&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;list_2--&amp;gt;D_rpt&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;list_3--&amp;gt;E_rpt F_rpt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2014 19:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro-variables-lists-based-on-the-value-of-another/m-p/154909#M298707</guid>
      <dc:creator>pradeepalankar</dc:creator>
      <dc:date>2014-03-24T19:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro variables lists based on the value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro-variables-lists-based-on-the-value-of-another/m-p/154910#M298708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A standard data step works nicely as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA SAMPLE;&lt;/P&gt;&lt;P&gt;LENGTH VAR_LIST $256.;&lt;/P&gt;&lt;P&gt;SET HAVE; &lt;/P&gt;&lt;P&gt;BY PAGE;&lt;/P&gt;&lt;P&gt;RETAIN VAR_LIST;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF FIRST.PAGE THEN VAR_LIST=RPT_VARIABLE;&lt;/P&gt;&lt;P&gt;ELSE VAR_LIST=CATX(" ", VAR_LIST, RPT_VARIABLE);&lt;/P&gt;&lt;P&gt;TEST=FIRST.PAGE;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF LAST.PAGE THEN DO;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CALL SYMPUTX("PAGE"||PUT(PAGE, 2. -L), VAR_LIST);&lt;/P&gt;&lt;P&gt;END;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;PAGE1.;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;PAGE2.;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;PAGE3.;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;PAGE4.;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2014 20:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro-variables-lists-based-on-the-value-of-another/m-p/154910#M298708</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-03-24T20:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro variables lists based on the value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro-variables-lists-based-on-the-value-of-another/m-p/154911#M298709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks to both of you for very helpful answers that worked great. Much appreciated!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2014 20:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro-variables-lists-based-on-the-value-of-another/m-p/154911#M298709</guid>
      <dc:creator>sgnolek</dc:creator>
      <dc:date>2014-03-24T20:45:13Z</dc:date>
    </item>
  </channel>
</rss>

