<?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 create macro or loop based on a list of values? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-or-loop-based-on-a-list-of-values/m-p/821128#M324172</link>
    <description>&lt;P&gt;&lt;SPAN&gt;It is likely one large table, with a variable representing the year is a better way to go. But its not clear to me how you would create these tables, do you really want to use your SQL code, or will the tables be created some other way?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Once you have these tables by year, what are you going to do with them?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jun 2022 13:17:49 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-06-30T13:17:49Z</dc:date>
    <item>
      <title>How to create macro or loop based on a list of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-or-loop-based-on-a-list-of-values/m-p/821126#M324170</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this isn't too difficult - but I'm having a hard time working out what I need to do in order to accomplish this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list of tables (for each year) which get created in various parts of my code that are currently hard-coded which I would like to be able to create using a macro (I think) based on a list of years which i determine at the start of my code.&lt;/P&gt;&lt;P&gt;The reason for this is I will need to re-run based on updated data and different years in the future and I don't want to have to edit every instance where I have hard-coded years into table creation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
DROP TABLE t_1819, t_1920, t_2021;
CREATE TABLE t_1819
(Group					VARCHAR	(2)
,Income_band_1819		SMALLINT	
,BHC_Frequency			DECIMAL	(10)
,AHC_Frequency			DECIMAL	(10)
,BHC_Gross				DECIMAL	(10)
,AHC_Gross				DECIMAL	(10)
);
CREATE TABLE t_1920
(Group					VARCHAR	(2)
,Income_band_1819		SMALLINT	
,BHC_Frequency			DECIMAL	(10)
,AHC_Frequency			DECIMAL	(10)
,BHC_Gross				DECIMAL	(10)
,AHC_Gross				DECIMAL	(10)
);
CREATE TABLE t_2021
(Group					VARCHAR	(2)
,Income_band_2021		SMALLINT	
,BHC_Frequency			DECIMAL	(10)
,AHC_Frequency			DECIMAL	(10)
,BHC_Gross				DECIMAL	(10)
,AHC_Gross				DECIMAL	(10)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there a way in which I can have a list of years at the start of my code (e.g. 1819, 1920, 2021, ... ) and then one process to create all tables by year in the one go? While also updating columns e.g. 'Income_band_ ...' with each year?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope that's clear - I'm just not sure what it is that I'm doing here.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 13:09:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-or-loop-based-on-a-list-of-values/m-p/821126#M324170</guid>
      <dc:creator>michael1212</dc:creator>
      <dc:date>2022-06-30T13:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to create macro or loop based on a list of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-or-loop-based-on-a-list-of-values/m-p/821128#M324172</link>
      <description>&lt;P&gt;&lt;SPAN&gt;It is likely one large table, with a variable representing the year is a better way to go. But its not clear to me how you would create these tables, do you really want to use your SQL code, or will the tables be created some other way?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Once you have these tables by year, what are you going to do with them?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 13:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-or-loop-based-on-a-list-of-values/m-p/821128#M324172</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-30T13:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to create macro or loop based on a list of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-or-loop-based-on-a-list-of-values/m-p/821129#M324173</link>
      <description>Hi,&lt;BR /&gt;It doesn't matter a lot to me how these are created, this is just how I have been creating them throughout the code. My processing also inserts the values based on the tables by year. I could change this if what you are suggesting makes more sense.&lt;BR /&gt;In the end they are exported to excel with each table (year) going into a different tab. I think I would like the end product to end up exporting in that way.&lt;BR /&gt;Thanks!</description>
      <pubDate>Thu, 30 Jun 2022 13:28:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-or-loop-based-on-a-list-of-values/m-p/821129#M324173</guid>
      <dc:creator>michael1212</dc:creator>
      <dc:date>2022-06-30T13:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to create macro or loop based on a list of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-or-loop-based-on-a-list-of-values/m-p/821133#M324175</link>
      <description>&lt;P&gt;Create one table, then export to Excel with different tabs by year, very simple. You would use ODS EXCEL to obtain tabs by year. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file="abcdef.xlsx" options(sheet_interval='BYGROUP' sheet_label='YEAR');
proc print data=have;
     by year;
     var x1 x2 x3 ... ; /* Put your real variable names here */
run;
ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see, no macros needed.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 13:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-or-loop-based-on-a-list-of-values/m-p/821133#M324175</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-30T13:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to create macro or loop based on a list of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-or-loop-based-on-a-list-of-values/m-p/821140#M324180</link>
      <description>I'll do that.&lt;BR /&gt;Thanks for the help!</description>
      <pubDate>Thu, 30 Jun 2022 14:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-macro-or-loop-based-on-a-list-of-values/m-p/821140#M324180</guid>
      <dc:creator>michael1212</dc:creator>
      <dc:date>2022-06-30T14:00:16Z</dc:date>
    </item>
  </channel>
</rss>

