<?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: Quarterly Date Macro in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Quarterly-Date-Macro/m-p/600582#M35011</link>
    <description>&lt;P&gt;Here how you can generate the list of desired table names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* create sample data */
%macro createSampleData();
  %do mm=1 %to 12;
    %let mm=%sysfunc(putn(&amp;amp;mm.,z2.));
    %do yyyy=2009 %to 2018;
      data loandata_&amp;amp;yyyy.&amp;amp;mm.;
        set sashelp.class(obs=3);
      run;
    %end;
  %end;
%mend;
%createSampleData();

/* create macro variable &amp;amp;dslist with list of table names beginning of quarter */
proc sql noprint;
  select catx('.',libname,memname) into :dslist separated by ' '
  from dictionary.tables
  where 
    libname='WORK' 
    and memname like 'LOANDATA^_%' escape '^'
    and input(scan(memname,2,'_'),yymmn6.) = intnx('quarter',input(scan(memname,2,'_'),yymmn6.),0,'b')
  ;
quit;
%put &amp;amp;=dslist;

/* create table want */
data want;
  length _sourceDS sourceDS $41;
  set &amp;amp;dslist indsname=_sourceDS;
  sourceDS=_sourceDS;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 30 Oct 2019 22:51:06 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-10-30T22:51:06Z</dc:date>
    <item>
      <title>Quarterly Date Macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Quarterly-Date-Macro/m-p/600064#M35006</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi I am trying to create a macro date variable for quarterly datasets. I am pulling data from 9+ years of datasets at quarterly intervals and the datasets have the name format of: loandata_YYYYMM. For example, I need a line of data from loandata_201801, loandata_201804, loandata_201807 and loandata_201810. I know how to write the macro manually (see code below), but I also know there is definitely a quicker way to write this. Each year we run this code, we will need the new year's quarterly data. The code below is the SUPER abbreviated version of what I have, it's missing the proc sql create table section and a few calculated variables. I just wanted to show the macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro extract_portfolio(date_input, month);

data ext_&amp;amp;date_input.&amp;amp;month.;
	set loandata_&amp;amp;date_input.&amp;amp;month. (keep=&amp;nbsp;yada&amp;nbsp;yada&amp;nbsp;yada);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%mend;
%extract_portfolio(2010, 10);
%extract_portfolio(2011, 01);
%extract_portfolio(2011, 04);
%extract_portfolio(2011, 07);
%extract_portfolio(2011, 10);
%extract_portfolio(2012, 01);
%extract_portfolio(2012, 04);
%extract_portfolio(2012, 07);
%extract_portfolio(2012, 10);
%extract_portfolio(2013, 01);
%extract_portfolio(2013, 04);


/* Add new year */

data home.portfolio_;
	set	home.portfolio_201010
		home.portfolio_201101
		home.portfolio_201104
		home.portfolio_201107
		home.portfolio_201110
		home.portfolio_201201
		home.portfolio_201204
		home.portfolio_201207
		home.portfolio_201210&lt;BR /&gt;                home.portfolio_201301&lt;BR /&gt;                home.portfolio_201304&lt;BR /&gt;;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 13:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Quarterly-Date-Macro/m-p/600064#M35006</guid>
      <dc:creator>claforest1</dc:creator>
      <dc:date>2019-10-29T13:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Quarterly Date Macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Quarterly-Date-Macro/m-p/600086#M35008</link>
      <description>&lt;P&gt;For now, you should forget about how to write this faster.&amp;nbsp; You should concentrate on how to design it better, so it will run in half the time.&amp;nbsp; Your design should aim for something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data home.portfolio_;
	set	loandata_201010 (keep=yada yada yada)
                loandata_201101 (keep=yada yada yada)
                loandata_201104 (keep=yada yada yada)
                .....
                ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Extract the data one time instead of twice.&amp;nbsp; Once you get it to work without macros, then worry about adding macros.&amp;nbsp; If you apply macros too soon, you will embed the inefficiencies forever.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2019 14:59:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Quarterly-Date-Macro/m-p/600086#M35008</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-10-29T14:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: Quarterly Date Macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Quarterly-Date-Macro/m-p/600091#M35009</link>
      <description>&lt;P&gt;Part of your problem will be how to generate the series of suffixes for the dataset names: 201010,201101,201104,....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do want to control what series to generate?&amp;nbsp; Do you want to start from a given month and specify a number of files?&amp;nbsp; Do you want to specify start and end dates?&amp;nbsp; Do you want to specify the dates as real dates? Or as the YYYYMM string that is used in the dataset names? or in the Year,Month combo like your posted example?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is how you might do it when user specifies a start date plus a count of the number of quarters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymacro(start,count);
%local i yymm;
%do i=1 %to &amp;amp;count;
   %let yymm=%sysfunc(intnx(qtr,&amp;amp;start,&amp;amp;i-1,b),yymmn6.);
   ... code that uses &amp;amp;YYMM as part of dataset name ....
%end;
%mend mymacro;

%mymacro('01oct2010'd,11);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;65    %macro mymacro(start,count);
66    %local i yymm;
67    %do i=1 %to &amp;amp;count;
68       %let yymm=%sysfunc(intnx(qtr,&amp;amp;start,&amp;amp;i-1,b),yymmn6.);
69       %put &amp;amp;=start &amp;amp;=i &amp;amp;=yymm ;
70    %end;
71    %mend mymacro;
72
73    %mymacro('01oct2010'd,11);
START='01oct2010'd I=1 YYMM=201010
START='01oct2010'd I=2 YYMM=201101
START='01oct2010'd I=3 YYMM=201104
START='01oct2010'd I=4 YYMM=201107
START='01oct2010'd I=5 YYMM=201110
START='01oct2010'd I=6 YYMM=201201
START='01oct2010'd I=7 YYMM=201204
START='01oct2010'd I=8 YYMM=201207
START='01oct2010'd I=9 YYMM=201210
START='01oct2010'd I=10 YYMM=201301
START='01oct2010'd I=11 YYMM=201304
&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Oct 2019 15:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Quarterly-Date-Macro/m-p/600091#M35009</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-29T15:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Quarterly Date Macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Quarterly-Date-Macro/m-p/600582#M35011</link>
      <description>&lt;P&gt;Here how you can generate the list of desired table names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* create sample data */
%macro createSampleData();
  %do mm=1 %to 12;
    %let mm=%sysfunc(putn(&amp;amp;mm.,z2.));
    %do yyyy=2009 %to 2018;
      data loandata_&amp;amp;yyyy.&amp;amp;mm.;
        set sashelp.class(obs=3);
      run;
    %end;
  %end;
%mend;
%createSampleData();

/* create macro variable &amp;amp;dslist with list of table names beginning of quarter */
proc sql noprint;
  select catx('.',libname,memname) into :dslist separated by ' '
  from dictionary.tables
  where 
    libname='WORK' 
    and memname like 'LOANDATA^_%' escape '^'
    and input(scan(memname,2,'_'),yymmn6.) = intnx('quarter',input(scan(memname,2,'_'),yymmn6.),0,'b')
  ;
quit;
%put &amp;amp;=dslist;

/* create table want */
data want;
  length _sourceDS sourceDS $41;
  set &amp;amp;dslist indsname=_sourceDS;
  sourceDS=_sourceDS;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Oct 2019 22:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Quarterly-Date-Macro/m-p/600582#M35011</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-10-30T22:51:06Z</dc:date>
    </item>
  </channel>
</rss>

