<?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 write macro or do loop to go over many years in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/write-macro-or-do-loop-to-go-over-many-years/m-p/877424#M346632</link>
    <description>&lt;P&gt;My code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have out=list(keep=name) noprint;
data list1; set list(keep=name); if name in ('ID','Name','Code','Country','Type','Form','Status','Entity'); keep name;
data list2; set list; if substr(name, length(name)-3) = 'YEAR' then output; keep name;

data l2; set list1 list2;

proc sql noprint; select name into :l2 separated by ' ' from l2; quit;

data want_YEAR(keep=&amp;amp;l2); set have;

proc sql noprint; select catx("=", name, substr(name, 1, length(name)-5)) into :rename_list separated by " "
	from sashelp.vcolumn where libname='WORK' and memname='HAVE_YEAR' and upper(trim(name)) like '%_YEAR'; quit;
proc datasets library=work nodetails nolist; modify have_YEAR; rename &amp;amp;rename_list; run; quit;

data final; set have_YEAR;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have ran this code by replacing YEAR with the years I want and repeat the code for as many years as I needed. Now I need to run it over quite a few number of years so I need to automate it. How can I do this?&lt;/P&gt;</description>
    <pubDate>Thu, 25 May 2023 02:05:24 GMT</pubDate>
    <dc:creator>Satori</dc:creator>
    <dc:date>2023-05-25T02:05:24Z</dc:date>
    <item>
      <title>write macro or do loop to go over many years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-macro-or-do-loop-to-go-over-many-years/m-p/877424#M346632</link>
      <description>&lt;P&gt;My code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have out=list(keep=name) noprint;
data list1; set list(keep=name); if name in ('ID','Name','Code','Country','Type','Form','Status','Entity'); keep name;
data list2; set list; if substr(name, length(name)-3) = 'YEAR' then output; keep name;

data l2; set list1 list2;

proc sql noprint; select name into :l2 separated by ' ' from l2; quit;

data want_YEAR(keep=&amp;amp;l2); set have;

proc sql noprint; select catx("=", name, substr(name, 1, length(name)-5)) into :rename_list separated by " "
	from sashelp.vcolumn where libname='WORK' and memname='HAVE_YEAR' and upper(trim(name)) like '%_YEAR'; quit;
proc datasets library=work nodetails nolist; modify have_YEAR; rename &amp;amp;rename_list; run; quit;

data final; set have_YEAR;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have ran this code by replacing YEAR with the years I want and repeat the code for as many years as I needed. Now I need to run it over quite a few number of years so I need to automate it. How can I do this?&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 02:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-macro-or-do-loop-to-go-over-many-years/m-p/877424#M346632</guid>
      <dc:creator>Satori</dc:creator>
      <dc:date>2023-05-25T02:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: write macro or do loop to go over many years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-macro-or-do-loop-to-go-over-many-years/m-p/877434#M346637</link>
      <description>&lt;P&gt;Don't keep data (years) in structure (variable names). Also see Maxim 19.&lt;/P&gt;
&lt;P&gt;Transpose the year... variables to a long dataset and extract tze year number from _NAME_. Everything will then turn into a simple WHERE or BY.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 03:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-macro-or-do-loop-to-go-over-many-years/m-p/877434#M346637</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-25T03:51:12Z</dc:date>
    </item>
  </channel>
</rss>

