<?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: Looping through a Macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/627103#M185031</link>
    <description>&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;The &lt;STRONG&gt;BY&lt;/STRONG&gt; statement actually worked.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Feb 2020 05:36:58 GMT</pubDate>
    <dc:creator>Pumpp</dc:creator>
    <dc:date>2020-02-25T05:36:58Z</dc:date>
    <item>
      <title>Looping through a Macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626447#M184772</link>
      <description>&lt;P&gt;Below is the code which works fine and gives results as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro Variables(class1=);&lt;/P&gt;&lt;P&gt;proc tabulate data=work.policy_consolidated01 missing;&lt;BR /&gt;class year;&lt;BR /&gt;class quarter;&lt;BR /&gt;class type;&lt;BR /&gt;class Concat;&lt;/P&gt;&lt;P&gt;var No_of_policies;&lt;BR /&gt;var premium;&lt;BR /&gt;var Avg_Premium / weight = No_of_Policies;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;table (year=' ')*(quarter=' ' all='Sub Total'),&lt;BR /&gt;sum=' '*(no_of_policies='NOP'*Format=comma16.0&lt;BR /&gt;premium='Prem'*Format=comma16.0)&lt;/P&gt;&lt;P&gt;mean=' '*(Avg_Premium='Avg Prem'*Format=comma16.0)&lt;BR /&gt;/printmiss nocellmerge box='year'; title &amp;amp;class1;&lt;BR /&gt;where year in ('2017','2016','2015', '2014', '2013') and Concat = &amp;amp;class1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%Mend;&lt;BR /&gt;%Variables(class1='AA');&lt;BR /&gt;%Variables(class1='AB');&lt;BR /&gt;%Variables(class1='AC');&lt;BR /&gt;%Variables(class1='BA');&lt;BR /&gt;%Variables(class1='BB');&lt;BR /&gt;%Variables(class1='CE');&lt;/P&gt;&lt;P&gt;etc....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are 30 unique Concat observations. Instead of manually writing all the &amp;amp;class1 variables, I want a code such that it it loops through each of the 30 unique Concat observations and produces the same results.&lt;/P&gt;&lt;P&gt;Also is this looping possible if there are more than 1 class variables?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 12:38:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626447#M184772</guid>
      <dc:creator>Pumpp</dc:creator>
      <dc:date>2020-02-21T12:38:31Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a Macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626449#M184773</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310998"&gt;@Pumpp&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please try this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table Concat_list as select distinct Concat from work.policy_consolidated01;
quit;

data _null_;
	set Concat_list;
	rc = dosubl(cats('%Variables(class1="',Concat,'");'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table Concat_list as select distinct Concat from work.policy_consolidated01;
quit;

data _null_;
	set Concat_list;
	call execute (cats('%Variables(class1="',Concat,'");'));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Feb 2020 13:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626449#M184773</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-21T13:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a Macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626450#M184774</link>
      <description>&lt;P&gt;Nice use of DoSubl!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 13:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626450#M184774</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-02-21T13:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a Macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626456#M184779</link>
      <description>&lt;P&gt;Where does the list of values that you want to use in your macro calls come from?&amp;nbsp; Do you have it in a dataset? Or just as a text string somewhere?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really need to macro?&lt;/P&gt;
&lt;P&gt;If the list is just from the same input dataset then why not just modify the TABLE statement to use CONCAT as the page dimension?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=work.policy_consolidated01 missing;
  class year quarter type Concat;
  var No_of_policies premium;  
  var Avg_Premium / weight = No_of_Policies;
  table concat
      , (year=' ')*(quarter=' ' all='Sub Total')
      , sum=' '*(no_of_policies='NOP'*Format=comma16.0
        premium='Prem'*Format=comma16.0)
        mean=' '*(Avg_Premium='Avg Prem'*Format=comma16.0)
     /printmiss nocellmerge box='year'
  ; 
  where year in ('2017','2016','2015', '2014', '2013')
      and Concat in ('AA','AB')
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if the data is sorted then use it as a BY variable instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=work.policy_consolidated01 missing;
  by concat;
  class year quarter type ;
  var No_of_policies premium;  
  var Avg_Premium / weight = No_of_Policies;
  table (year=' ')*(quarter=' ' all='Sub Total')
      , sum=' '*(no_of_policies='NOP'*Format=comma16.0
        premium='Prem'*Format=comma16.0)
        mean=' '*(Avg_Premium='Avg Prem'*Format=comma16.0)
    /printmiss nocellmerge box='year'
  ; 
  where year in ('2017','2016','2015', '2014', '2013')
      and Concat in ('AA','AB')
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Feb 2020 13:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626456#M184779</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-21T13:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a Macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626799#M184912</link>
      <description>&lt;P&gt;I am getting an error message.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Where do I put the &lt;STRONG&gt;%macro Variables(class1=);&amp;nbsp;&lt;/STRONG&gt;statement?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And also I want the Results(in tabular form) not output. Is it possible to use the&amp;nbsp;&lt;STRONG&gt;dosubl &lt;/STRONG&gt;syntax or &lt;STRONG&gt;call execute&lt;/STRONG&gt;&amp;nbsp;syntax in Proc tabulate?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Like i said, I have 30+ unique concat observations, and I want 30+ seperate results and then export those 30+ results in excel.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The method I used gave me the desired output, but i had to manually write all those 30+ class variables to get the output. I want a code like &lt;STRONG&gt;dosubl &lt;/STRONG&gt;or&lt;STRONG&gt; call execute&amp;nbsp;&lt;/STRONG&gt;that can be used in porc tabulate to get the same results.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 04:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626799#M184912</guid>
      <dc:creator>Pumpp</dc:creator>
      <dc:date>2020-02-24T04:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a Macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626801#M184914</link>
      <description>&lt;P&gt;I do not want concat to come in TABLE statement. I want it in the same format as shown in the code.&lt;/P&gt;&lt;P&gt;And also I do not want the total of all concat's. I want the where statement of concat to be one those 30+ distinct observations. And i want 30+ different results displayed, rather than one single result.&lt;/P&gt;&lt;P&gt;I want to see the results based on individual concat values.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 05:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626801#M184914</guid>
      <dc:creator>Pumpp</dc:creator>
      <dc:date>2020-02-24T05:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a Macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626862#M184943</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310998"&gt;@Pumpp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I do not want concat to come in TABLE statement. I want it in the same format as shown in the code.&lt;/P&gt;
&lt;P&gt;And also I do not want the total of all concat's. I want the where statement of concat to be one those 30+ distinct observations. And i want 30+ different results displayed, rather than one single result.&lt;/P&gt;
&lt;P&gt;I want to see the results based on individual concat values.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Making the report BY the concat values will make a separate report for each value of CONCAT.&amp;nbsp; You can either keep the automatic BY line or use the #BYVAL tag in your titles.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do want to generate one macro call per value of CONCAT you need to explain what is the source of the list of CONCAT values you want to use to drive the generation of the macro calls.&amp;nbsp; Do you have that in a dataset?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 13:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/626862#M184943</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-24T13:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through a Macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/627103#M185031</link>
      <description>&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;The &lt;STRONG&gt;BY&lt;/STRONG&gt; statement actually worked.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 05:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-through-a-Macro-variable/m-p/627103#M185031</guid>
      <dc:creator>Pumpp</dc:creator>
      <dc:date>2020-02-25T05:36:58Z</dc:date>
    </item>
  </channel>
</rss>

