<?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: how to update a list of year in a macro variable automatically in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968757#M45991</link>
    <description>&lt;P&gt;And here is some update:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro makeListDT(s,e);
%do s=&amp;amp;s. %to %sysfunc(year(&amp;amp;e.)); &amp;amp;s.%end;
%mend makeListDT;

%let yearlist2=%makeListDT(2001,"11jun2025"d);
%put &amp;amp;yearlist2.;

%let yearlist3=%makeListDT(2001,%sysfunc(today()));
%put &amp;amp;yearlist3.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Wed, 11 Jun 2025 16:18:15 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2025-06-11T16:18:15Z</dc:date>
    <item>
      <title>how to update a list of year in a macro variable automatically</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968753#M45989</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macro variable yearlist.&lt;BR /&gt;&lt;BR /&gt;Is there a way to define / upgrade it until the current year ?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yearlist=2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would like to have:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;some thing like %let yearlist2=2001--year(date());&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Jun 2025 16:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968753#M45989</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-06-11T16:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to update a list of year in a macro variable automatically</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968756#M45990</link>
      <description>&lt;P&gt;Let's start simple:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro makeList(s,e);
%do s=&amp;amp;s. %to &amp;amp;e.; &amp;amp;s.%end;
%mend makeList;

%let yearlist=%makeList(2001,2025);
%put &amp;amp;yearlist.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 16:15:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968756#M45990</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-06-11T16:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to update a list of year in a macro variable automatically</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968757#M45991</link>
      <description>&lt;P&gt;And here is some update:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro makeListDT(s,e);
%do s=&amp;amp;s. %to %sysfunc(year(&amp;amp;e.)); &amp;amp;s.%end;
%mend makeListDT;

%let yearlist2=%makeListDT(2001,"11jun2025"d);
%put &amp;amp;yearlist2.;

%let yearlist3=%makeListDT(2001,%sysfunc(today()));
%put &amp;amp;yearlist3.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 16:18:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968757#M45991</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-06-11T16:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to update a list of year in a macro variable automatically</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968759#M45992</link>
      <description>&lt;P&gt;I would say that in my experience, such a macro variable like &amp;amp;yearlist with 23 consecutive years listed is rarely needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have macro variables &amp;amp;startyear and &amp;amp;endyear, you could use these in a DATA step. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where year between &amp;amp;startyear and &amp;amp;endyear;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something very similar would work in SQL&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 16:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968759#M45992</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-06-11T16:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to update a list of year in a macro variable automatically</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968762#M45993</link>
      <description>&lt;P&gt;Use a DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  length yearlist $500;
  do year=2001 to year(date());
     yearlist=catx(' ',yearlist,year);
  end;
  call symputx('yearlist',yearlist);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could do it in macro code, but you would need to define a macro and then call it to be able to run a %DO loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why do you want that list?&lt;/P&gt;
&lt;P&gt;If you plan to use it to generate SAS code like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;year in (2001 2002 ... 2024 2025)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then why not just generate&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;year in (2001:2025)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That you could put into a macro variable pretty easily.&amp;nbsp; If you just want the last year to be the year your SAS session started you could use last four characters of the SYSDATE9 automatic macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yearlist=2001:%substr(&amp;amp;sysdate9,6);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If instead you need to actual current year (in case your SAS session started last year) then use&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yearlist=2001:%sysfunc(date(),year4.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Jun 2025 17:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968762#M45993</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-06-11T17:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to update a list of year in a macro variable automatically</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968764#M45994</link>
      <description>&lt;P&gt;In data step you can go without loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  array Y[2001:%sysfunc(date(),year4.)] (2001:%sysfunc(date(),year4.));
  call symputx('yearlist',catx(" ", of Y[*]));
run;

%put &amp;amp;=yearlist;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or with a bit less keystrokes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let y=2001:%sysfunc(date(),year4.);
data _null_;
  array Y[&amp;amp;y.] (&amp;amp;y.);
  call symputx('yearlist',catx(" ", of Y[*]));
run;

%put &amp;amp;=yearlist;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 17:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968764#M45994</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-06-11T17:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to update a list of year in a macro variable automatically</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968765#M45995</link>
      <description>&lt;P&gt;I am using the yearlist in a loop like this one below.&amp;nbsp; I am using this approach because the other loop use a list of define cie subfolder and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yearlist=2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025;

%macro test;
%do k=1 %to %sysfunc(countw(&amp;amp;yearlist.));
%put %scan(&amp;amp;yearlist.,&amp;amp;k);
%end;

%mend test;
%test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So I am looking for a way to generate the yearlist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This one seems a good way&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  length yearlist $500;
  do year=2001 to year(date());
     yearlist=catx(' ',yearlist,year);
  end;
  call symputx('yearlist',yearlist);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;other idea ?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 17:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968765#M45995</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-06-11T17:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to update a list of year in a macro variable automatically</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968766#M45996</link>
      <description>&lt;P&gt;If you already have a %DO loop you are using for something else you could just use arithmetic to calculate the year.&lt;/P&gt;
&lt;P&gt;Say you already needed to extract a value for the MYVAR macro variable from the space delimited set of values stored in the MYLIST macro variable.&amp;nbsp; You could use the same looping index to calculate the YEAR value.&amp;nbsp; You just need to base year.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let baseyear=2001;
....
%do i=1 %to &amp;amp;nyears;
  %let myvar = %scan(&amp;amp;mylist,&amp;amp;i,%str( ));
  %let year=%eval(&amp;amp;baseyear + &amp;amp;i - 1);
....
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Jun 2025 17:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968766#M45996</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-06-11T17:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to update a list of year in a macro variable automatically</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968769#M45997</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am using the yearlist in a loop like this one below.&amp;nbsp; I am using this approach because the other loop use a list of define cie subfolder and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yearlist=2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025;

%macro test;
%do k=1 %to %sysfunc(countw(&amp;amp;yearlist.));
%put %scan(&amp;amp;yearlist.,&amp;amp;k);
%end;

%mend test;
%test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So I am looking for a way to generate the yearlist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why does it have to be a LIST of years? Why not this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
%do yr=&amp;amp;startyear %to &amp;amp;endyear;
%put &amp;amp;yr;
%end;
%mend;

%test&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But looking at the big picture, we see many people creating macro loops when that is completely unnecessary and it is an unneeded complication to the code. Could you also achieve something similar with much similar coding using&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by year;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in one or more places in your analysis? The BY statement essentially creates a loop for you, without any complicated programming. Please&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;convince me that the BY statement won't work in your situation.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 18:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968769#M45997</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-06-11T18:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to update a list of year in a macro variable automatically</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968803#M46004</link>
      <description>&lt;P&gt;I am a SQL guy, just for having some fun .&lt;/P&gt;
&lt;PRE&gt;data x;
 do year=2001 to year(date());
  output;
 end;
run;
proc sql noprint;
select year into :yearlist separated by ' ' from x;
quit;

%put &amp;amp;=yearlist.;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Jun 2025 02:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-update-a-list-of-year-in-a-macro-variable-automatically/m-p/968803#M46004</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-06-12T02:46:24Z</dc:date>
    </item>
  </channel>
</rss>

