<?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: Year macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624164#M183817</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro _year_inc (Y_start, Y_end);
	%do year= &amp;amp;Y_start %to &amp;amp;Y_end;
		data new_data_&amp;amp;year;
		run;
	%end;
%mend;

%_year_inc(2013,2016)&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 12 Feb 2020 13:13:48 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-02-12T13:13:48Z</dc:date>
    <item>
      <title>Year macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624159#M183812</link>
      <description>&lt;P&gt;Looking to create a &amp;amp;year&amp;nbsp;macro that will increment by year for 2013-2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my datasets for 2013 to 2016&amp;nbsp;can be named as such:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;new_data_&amp;amp;year:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;new_data_2013&lt;/P&gt;&lt;P&gt;new_data_2014&lt;/P&gt;&lt;P&gt;new_data_2015&lt;/P&gt;&lt;P&gt;new_data_2016&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 13:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624159#M183812</guid>
      <dc:creator>AP718</dc:creator>
      <dc:date>2020-02-12T13:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Year macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624164#M183817</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro _year_inc (Y_start, Y_end);
	%do year= &amp;amp;Y_start %to &amp;amp;Y_end;
		data new_data_&amp;amp;year;
		run;
	%end;
%mend;

%_year_inc(2013,2016)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Feb 2020 13:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624164#M183817</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-12T13:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Year macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624165#M183818</link>
      <description>Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 12 Feb 2020 13:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624165#M183818</guid>
      <dc:creator>AP718</dc:creator>
      <dc:date>2020-02-12T13:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: Year macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624167#M183819</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/140206"&gt;@AP718&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're welcome&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 13:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624167#M183819</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-12T13:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: Year macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624168#M183820</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/140206"&gt;@AP718&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another approach could be :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	do year = 2013 to 2016;
		rc = dosubl(cats('data new2_data_',year,';run;'));
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;-&amp;gt; the DOSUBL function enables the immediate execution of code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 13:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624168#M183820</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-12T13:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Year macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624205#M183843</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One remark about DoSubL() function. Considering all of it's advantages there is one significant disadvantage - speed. If you consider the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let t=%sysfunc(time());
data _null_;
	do year = 2001 to 2010;
		rc = dosubl(cats('data new2_data_',year,';run;'));
		output;
	end;
run;
%put %sysevalf(%sysfunc(time()) - &amp;amp;t.);

%let t=%sysfunc(time());
%macro _year_inc (Y_start, Y_end);
	%do year= &amp;amp;Y_start %to &amp;amp;Y_end;
		data new_data_&amp;amp;year;
		run;
	%end;
%mend;

%_year_inc(1901,1910)
%put %sysevalf(%sysfunc(time()) - &amp;amp;t.);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;you can see that it was much longer for dosubl() to generate (only) 10 datasets, the log:&lt;/P&gt;&lt;PRE&gt;1
2     %let t=%sysfunc(time());
3     data _null_;
4       do year = 2001 to 2010;
5         rc = dosubl(cats('data new2_data_',year,';run;'));
6         output;
7       end;
8     run;

NOTE: The data set WORK.NEW2_DATA_2001 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


NOTE: The data set WORK.NEW2_DATA_2002 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


NOTE: The data set WORK.NEW2_DATA_2003 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


NOTE: The data set WORK.NEW2_DATA_2004 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


NOTE: The data set WORK.NEW2_DATA_2005 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


NOTE: The data set WORK.NEW2_DATA_2006 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


NOTE: The data set WORK.NEW2_DATA_2007 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


NOTE: The data set WORK.NEW2_DATA_2008 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


NOTE: The data set WORK.NEW2_DATA_2009 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


NOTE: The data set WORK.NEW2_DATA_2010 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


NOTE: DATA statement used (Total process time):
      real time           13.85 seconds
      cpu time            8.86 seconds


9     %put %sysevalf(%sysfunc(time()) - &amp;amp;t.);
13.8770000934018
10
11    %let t=%sysfunc(time());
12    %macro _year_inc (Y_start, Y_end);
13      %do year= &amp;amp;Y_start %to &amp;amp;Y_end;
14        data new_data_&amp;amp;year;
15        run;
16      %end;
17    %mend;
18
19    %_year_inc(1901,1910)

NOTE: The data set WORK.NEW_DATA_1901 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds



NOTE: The data set WORK.NEW_DATA_1902 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.03 seconds



NOTE: The data set WORK.NEW_DATA_1903 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.03 seconds



NOTE: The data set WORK.NEW_DATA_1904 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds



NOTE: The data set WORK.NEW_DATA_1905 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds



NOTE: The data set WORK.NEW_DATA_1906 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds



NOTE: The data set WORK.NEW_DATA_1907 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds



NOTE: The data set WORK.NEW_DATA_1908 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds



NOTE: The data set WORK.NEW_DATA_1909 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds



NOTE: The data set WORK.NEW_DATA_1910 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds


20    %put %sysevalf(%sysfunc(time()) - &amp;amp;t.);
0.39300012589956&lt;/PRE&gt;&lt;P&gt;So it is&amp;nbsp;13.8770000934018 seconds for DoSubL() vs.&amp;nbsp;0.39300012589956 for macro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In general I think it is better to avoid looping over DoSubL(). In short words:&amp;nbsp;&lt;/P&gt;&lt;P&gt;DoSubL(with loop inside) - good practice&lt;/P&gt;&lt;P&gt;Loop over DoSubL() - bad practice&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In our case I think Call Execute() would be more robust:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let t=%sysfunc(time());
data _null_;
	do year = 1801 to 1810;
		call execute(cats('data new3_data_',year,';run;'));
	end;
run;
%put %sysevalf(%sysfunc(time()) - &amp;amp;t.);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;With timing:&amp;nbsp;&lt;STRIKE&gt;0.39300012589956&lt;/STRIKE&gt;&amp;nbsp;[EDIT] 0.47200012209941 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 15:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624205#M183843</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-02-12T15:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Year macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624210#M183847</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have not had the opportunity to use dosubl / call execute on large amount of data, so thank you for the clarification!&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 15:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/624210#M183847</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-12T15:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: Year macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/682960#M206778</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I create a macro variable for the prior year, current year and future year. The prior year will be the current year minus one year, future year will be the current year plus one year. So it will look something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let cy= 2020&lt;/P&gt;
&lt;P&gt;%let fy = &amp;amp;cy+1 (2021)&lt;/P&gt;
&lt;P&gt;%let py = &amp;amp;cy-1 (2019)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2020 15:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/682960#M206778</guid>
      <dc:creator>AP718</dc:creator>
      <dc:date>2020-09-10T15:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Year macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/682966#M206783</link>
      <description>&lt;P&gt;Remember to put semi-colons on the end of your SAS commands!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let cy= 2020;
%let fy = %eval(&amp;amp;cy+1);
%let py = %eval(&amp;amp;cy-1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Sep 2020 15:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/682966#M206783</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-10T15:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Year macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/682974#M206788</link>
      <description>Thank you!</description>
      <pubDate>Thu, 10 Sep 2020 15:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-macro/m-p/682974#M206788</guid>
      <dc:creator>AP718</dc:creator>
      <dc:date>2020-09-10T15:43:32Z</dc:date>
    </item>
  </channel>
</rss>

