<?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: easy macro: looping on a data set to select and aggregate data in another data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/easy-macro-looping-on-a-data-set-to-select-and-aggregate-data-in/m-p/288888#M59625</link>
    <description>&lt;P&gt;If you already have working code, then you just need to parameterise that code to make a macro:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as 
  select * from SASHELP.CARS;
quit;&lt;/PRE&gt;
&lt;P&gt;Could become:&lt;/P&gt;
&lt;PRE&gt;%macro Create_Table (ds=,frm=);
  proc sql;
    create table &amp;amp;DS. as
    select * from &amp;amp;FRM.;
  quit;
%mend Create_Table;

%Create_Table (ds=WANT,frm=SASHELP.CARS);&lt;/PRE&gt;
&lt;P&gt;However, in my experience, macro code merely complicates processes and in 99% of cases is not worth it in the first place, as SAS Base has inbuilt functionality to do things.&lt;/P&gt;</description>
    <pubDate>Tue, 02 Aug 2016 10:11:21 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-08-02T10:11:21Z</dc:date>
    <item>
      <title>easy macro: looping on a data set to select and aggregate data in another data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/easy-macro-looping-on-a-data-set-to-select-and-aggregate-data-in/m-p/288879#M59623</link>
      <description>&lt;P&gt;Dear experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here my input data:&lt;/P&gt;&lt;P&gt;1. a data set where for each id I specify the time period with begin and end (YYYMM)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;data T00_00_PTF;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;input reference_period: $12. begin: comma5. end: comma5.;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;datalines;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;current_month 201606 201606&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;previous_month 201605 201605&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;previous_12m 201507 201606&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;previous_36m 201307 201606&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;data T00_00_PTF;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;set T00_00_PTF;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;id=cats(reference_period,"_",begin,"_",end)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;;run;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. a data set of row data where the field date define the YYYYMM:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input date: comma5. revenue: comma5. shop: $12. country: $2.;&lt;BR /&gt;datalines;&lt;BR /&gt;201606 10000 ABC UK&lt;BR /&gt;201606 20000 A JP&lt;BR /&gt;201605 30000 A JP&lt;BR /&gt;201508 40000 A JP&lt;BR /&gt;201605 30000 BC UK&lt;BR /&gt;201308 20000 BC UK&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;on the base of the table T00_00_ptf I would like create another data set have which is expanding the initial data set have, adding to each observation the field id from the data set T00_00_ptf in the case that the variable data is in the time range. Here the output that I expect for the first observation (date=201606 =&amp;gt; included in all the subset defined in the table T00_00_PTF)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;data want;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;input id: $25. date: comma5. revenue: comma5. shop: $12. country: $2.;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;datalines;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;current_mont_201606_201606 201606 10000 ABC UK&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;previous_mon_201605_201605 201606 10000 ABC UK&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;previous_12m_201507_201606 201606 10000 ABC UK&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;previous_36m_201307_201606 201606 10000 ABC UK&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestion? I tried using a proc sql with the left outer join (left outer join T00_00_ptf t5. on (t5.begin=&amp;lt;t0.date and t0.date&amp;lt;=t5.end) but actually I would like to run it with a macro, so I can use it in the future also for different purposes.&lt;/P&gt;&lt;P&gt;Thanks a lot, SH.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 09:36:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/easy-macro-looping-on-a-data-set-to-select-and-aggregate-data-in/m-p/288879#M59623</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-08-02T09:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: easy macro: looping on a data set to select and aggregate data in another data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/easy-macro-looping-on-a-data-set-to-select-and-aggregate-data-in/m-p/288888#M59625</link>
      <description>&lt;P&gt;If you already have working code, then you just need to parameterise that code to make a macro:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as 
  select * from SASHELP.CARS;
quit;&lt;/PRE&gt;
&lt;P&gt;Could become:&lt;/P&gt;
&lt;PRE&gt;%macro Create_Table (ds=,frm=);
  proc sql;
    create table &amp;amp;DS. as
    select * from &amp;amp;FRM.;
  quit;
%mend Create_Table;

%Create_Table (ds=WANT,frm=SASHELP.CARS);&lt;/PRE&gt;
&lt;P&gt;However, in my experience, macro code merely complicates processes and in 99% of cases is not worth it in the first place, as SAS Base has inbuilt functionality to do things.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 10:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/easy-macro-looping-on-a-data-set-to-select-and-aggregate-data-in/m-p/288888#M59625</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-02T10:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: easy macro: looping on a data set to select and aggregate data in another data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/easy-macro-looping-on-a-data-set-to-select-and-aggregate-data-in/m-p/288890#M59626</link>
      <description>&lt;P&gt;The solution you describe seems OK to me. Since you do not indicate which other purposes you want to&lt;/P&gt;
&lt;P&gt;use your program for, it is difficult to give you an answer.&lt;/P&gt;
&lt;P&gt;Also, i think &lt;EM&gt;previous_month&lt;/EM&gt; should not be included in your want dataset since begin and end are 201605.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 10:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/easy-macro-looping-on-a-data-set-to-select-and-aggregate-data-in/m-p/288890#M59626</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-08-02T10:12:35Z</dc:date>
    </item>
  </channel>
</rss>

