<?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: Macros date ranges in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489708#M31607</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know this is not a full solution, it's intended to get you started, I"m assuming you would tailor it to your circumstances. What did you try? What exactly doesn't work? Post your code and log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And, quarter 3 doesn't make sense to be only 3 months. That to me would be Month 3. A Quarter is 3 months by definition so you may want to clarify your terminology or consider aligning it with SAS's to make it easier. If you're going to use your own definitions you'll have to add a lot of IF/THEN conditions to your data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Aug 2018 17:20:40 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-08-24T17:20:40Z</dc:date>
    <item>
      <title>Macros date ranges</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489665#M31598</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help designing a SAS macro procedure that will allow the aggregation of my tables by dates. For example in I have the following tables in my database:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My library name is data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the tables within my library:&lt;/P&gt;&lt;P&gt;data.sample_201805&lt;/P&gt;&lt;P&gt;data.sample_&lt;FONT color="#FF0000"&gt;201806&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data.sample_&lt;FONT color="#FF0000"&gt;201807&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data.sample_&lt;FONT color="#FF0000"&gt;201808&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data.sample_&lt;FONT color="#FF0000"&gt;201809&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to be able to call a macro that will create a new table by periods (quarterly, semiannually, yearly, etc...)&amp;nbsp;For instance for quarter 3: I want to be able to create a table with start date:&amp;nbsp;sample_201806 and for end date:&amp;nbsp;sample_201809.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can do it manually with this code below, but it is really time consuming. Hope someone one will be able to help. Thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data quarter_3;&lt;/P&gt;&lt;P&gt;set&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data.sample_&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;201806&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;data.sample_&lt;/SPAN&gt;&lt;/FONT&gt;201807&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;data.sample_&lt;/SPAN&gt;&lt;/FONT&gt;201808&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;data.sample_&lt;/SPAN&gt;&lt;/FONT&gt;201809&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2018 16:07:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489665#M31598</guid>
      <dc:creator>samface</dc:creator>
      <dc:date>2018-08-24T16:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macros date ranges</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489669#M31599</link>
      <description>&lt;P&gt;If you are allows dealing with sequential named files then&lt;/P&gt;
&lt;P&gt;set&amp;nbsp;&lt;SPAN&gt;data.sample_&lt;/SPAN&gt;&lt;FONT color="#ff0000"&gt;201806&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT size="4"&gt;&amp;nbsp;-&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#ff0000"&gt; &lt;FONT color="#ff0000"&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;data.sample_&lt;/SPAN&gt;&lt;/FONT&gt;201809 &lt;/FONT&gt;&lt;/FONT&gt;;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Will suffice, so you only "need" two macro variables.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2018 16:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489669#M31599</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-24T16:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macros date ranges</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489673#M31600</link>
      <description>&lt;P&gt;Thanks for the quick reply. I was in fact able to repodruce the tables using the iphen. Thanks for this tip, would you know how I could use a macro to do this?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2018 16:21:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489673#M31600</guid>
      <dc:creator>samface</dc:creator>
      <dc:date>2018-08-24T16:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macros date ranges</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489683#M31602</link>
      <description>&lt;P&gt;This is the basic idea. You'll have to look up INTNX to see what the valid intervals are and if it's close to what you want. You may need to modify it to handle all the intervals you need and to ensure the dates align but it's enough to get you started.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Didn't test this because I don't have data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Rather than set you could also loop with PROC APPEND to combine the data. Not sure if it's faster or not, but may be since it copies the file at once. If you wanted to do any calculations or add in any values you wouldn't be able to do that though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro combine_data(start_date=, interval=, increment=, dsout=);


data demo;
start_date = input("&amp;amp;start_date", yymmdd10.);
end_date =intnx("&amp;amp;interval", start_date, &amp;amp;increment, 'b');
format start_date end_date yymmn6.;

*create macro variables;
call symputx('date_s', start_date);
call symputx('date_e', end_date);

run;

data &amp;amp;dsout.;
set Data&amp;amp;date_s. - Data&amp;amp;date_e.;
run;

%mend;

%combine_data(start_date=20180101, interval=Quarter, increment=3, dsout=TEST123);&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Aug 2018 16:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489683#M31602</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-24T16:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macros date ranges</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489705#M31606</link>
      <description>Thanks for the code &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; but i am not able to get the results I am waiting for.</description>
      <pubDate>Fri, 24 Aug 2018 17:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489705#M31606</guid>
      <dc:creator>samface</dc:creator>
      <dc:date>2018-08-24T17:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macros date ranges</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489708#M31607</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know this is not a full solution, it's intended to get you started, I"m assuming you would tailor it to your circumstances. What did you try? What exactly doesn't work? Post your code and log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And, quarter 3 doesn't make sense to be only 3 months. That to me would be Month 3. A Quarter is 3 months by definition so you may want to clarify your terminology or consider aligning it with SAS's to make it easier. If you're going to use your own definitions you'll have to add a lot of IF/THEN conditions to your data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2018 17:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489708#M31607</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-24T17:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macros date ranges</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489742#M31609</link>
      <description>&lt;P&gt;Thanks again&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I was able to get the results expected. I basically defined a macro with&amp;nbsp; beginning and ending tables as follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%maco combine(table_beg=, table_end=, dsout=);&lt;/P&gt;&lt;P&gt;data &amp;amp;dsout.;&lt;/P&gt;&lt;P&gt;set libname.&amp;amp;table_beg. - libname.&amp;amp;table_end.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%combine (table_beg= , table_end= , dsout= ,)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully this code will guide someone else.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks again guys!!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2018 19:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros-date-ranges/m-p/489742#M31609</guid>
      <dc:creator>samface</dc:creator>
      <dc:date>2018-08-24T19:46:25Z</dc:date>
    </item>
  </channel>
</rss>

