<?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: Loop Code - Annual Rate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/587416#M167778</link>
    <description>&lt;P&gt;This might suit you:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*POPULATION FILE VARIABLES*/

%macro loop;

%local year;
%do year=2006 %to 2018;

  %let pop_years = pop&amp;amp;year ;
  %let sum_years = pop&amp;amp;year;
  %let pop_age = (AGEGROUP ne '');
  %let n_years = 1;
  %let geogdenom = FIPS_STATE IN (16, 41, 53);
  %let pop_race_sex = (RACE = 1);

  /*CASE FILE VARIABLES**/
  %let dataset = Q ;
  %let year = (year=&amp;amp;year);
  %let age = (agegroup ne '') ;
  %let geognum = FIPS_STATE_RES IN (16, 41, 53);
  %let race = (race = 1) ;
  %let sex = (sex ne '') ;
  %let cause = QR = 1;

  /*OUTPUT DESCRIPTORS*/
  %let time = "&amp;amp;year";
  %let measure = ' Q Deaths';
  %let racesexage = 'Race1, Region Name, Both Sex, All Ages';

  %Race1RATE;
%end;
%mend; 
%loop;
 

 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Sep 2019 04:11:44 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-09-10T04:11:44Z</dc:date>
    <item>
      <title>Loop Code - Annual Rate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/587395#M167772</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to calculate annual rates of various diseases for various populations. I&amp;nbsp; already have code that uses multiple macros to grab the corresponding population data and everything else I need. What I don't know how to do (new SAS user), is make my code repeat itself for the next year, then the next year, etc, until a certain year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, the code below does everything I want for the year 2006. I want it to re-run for 2007, then 2008, etc, until 2016.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*POPULATION FILE VARIABLES*/&lt;/P&gt;&lt;P&gt;%let pop_years = pop2006 ;&lt;BR /&gt;%let sum_years = pop2006;&lt;BR /&gt;%let pop_age = (AGEGROUP ne '');&lt;BR /&gt;%let n_years = 1;&lt;BR /&gt;%let geogdenom = FIPS_STATE IN (16, 41, 53);&lt;BR /&gt;%let pop_race_sex = (RACE = 1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*CASE FILE VARIABLES**/&lt;/P&gt;&lt;P&gt;%let dataset = Q ;&lt;BR /&gt;%let year = (year=2006);&lt;BR /&gt;%let age = (agegroup ne '') ;&lt;BR /&gt;%let geognum = FIPS_STATE_RES IN (16, 41, 53);&lt;BR /&gt;%let race = (race = 1) ;&lt;BR /&gt;%let sex = (sex ne '') ;&lt;BR /&gt;%let cause = QR = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*OUTPUT DESCRIPTORS*/&lt;/P&gt;&lt;P&gt;%let time = '2006';&lt;BR /&gt;%let measure = ' Q Deaths';&lt;BR /&gt;%let racesexage = 'Race1, Region Name, Both Sex, All Ages';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Race1RATE;&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;P&gt;This is an output example of what I currently get:&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV align="left"&gt;&lt;DIV class="branch"&gt;&lt;DIV align="left"&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="left"&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="left"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Population&lt;/TD&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;TD&gt;Count&lt;/TD&gt;&lt;TD&gt;Pop&lt;/TD&gt;&lt;TD&gt;Rate&lt;/TD&gt;&lt;TD&gt;CI_Lower&lt;/TD&gt;&lt;TD&gt;CI_Upper&lt;/TD&gt;&lt;TD&gt;CI_LB&lt;/TD&gt;&lt;TD&gt;CI_UB&lt;/TD&gt;&lt;TD&gt;Ann_pop&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Region, Both Sex, All Ages&lt;/TD&gt;&lt;TD&gt;2006&lt;/TD&gt;&lt;TD&gt;1063&lt;/TD&gt;&lt;TD&gt;11510305&lt;/TD&gt;&lt;TD&gt;8.98953&lt;/TD&gt;&lt;TD&gt;8.43434&lt;/TD&gt;&lt;TD&gt;9.54471&lt;/TD&gt;&lt;TD&gt;0.55518&lt;/TD&gt;&lt;TD&gt;0.55518&lt;/TD&gt;&lt;TD&gt;11510305&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Ideal output would have additional lines for the years 2007, 2008, etc up to 2016.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 10 Sep 2019 01:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/587395#M167772</guid>
      <dc:creator>hlovejoy</dc:creator>
      <dc:date>2019-09-10T01:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Code - Annual Rate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/587400#M167773</link>
      <description>&lt;P&gt;Welcome the the SAS community!&lt;/P&gt;
&lt;P&gt;With what you give us, we can only attempt to create several tables.&lt;/P&gt;
&lt;P&gt;In order to create a single table and add rows, we'd need to know how the table is created.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 02:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/587400#M167773</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-09-10T02:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Code - Annual Rate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/587413#M167775</link>
      <description>If you give me something that will create multiple tables, that is fine. Ideally looking for how to just loop the code I provided above, but adding 1 to the year each time until a specified end year.&lt;BR /&gt;Thank you!</description>
      <pubDate>Tue, 10 Sep 2019 04:05:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/587413#M167775</guid>
      <dc:creator>hlovejoy</dc:creator>
      <dc:date>2019-09-10T04:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Code - Annual Rate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/587416#M167778</link>
      <description>&lt;P&gt;This might suit you:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*POPULATION FILE VARIABLES*/

%macro loop;

%local year;
%do year=2006 %to 2018;

  %let pop_years = pop&amp;amp;year ;
  %let sum_years = pop&amp;amp;year;
  %let pop_age = (AGEGROUP ne '');
  %let n_years = 1;
  %let geogdenom = FIPS_STATE IN (16, 41, 53);
  %let pop_race_sex = (RACE = 1);

  /*CASE FILE VARIABLES**/
  %let dataset = Q ;
  %let year = (year=&amp;amp;year);
  %let age = (agegroup ne '') ;
  %let geognum = FIPS_STATE_RES IN (16, 41, 53);
  %let race = (race = 1) ;
  %let sex = (sex ne '') ;
  %let cause = QR = 1;

  /*OUTPUT DESCRIPTORS*/
  %let time = "&amp;amp;year";
  %let measure = ' Q Deaths';
  %let racesexage = 'Race1, Region Name, Both Sex, All Ages';

  %Race1RATE;
%end;
%mend; 
%loop;
 

 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 04:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/587416#M167778</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-09-10T04:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Code - Annual Rate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/587540#M167832</link>
      <description>&lt;P&gt;This looks almost like attempting to make the macro language do some sort of proc summary with multiple class variables and a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I might suggest providing a small example of your data and what you want for output from that data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what your Race1Rate macro looks like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that setting many values outside of a macro and assuming that another macro, such as your Race1Rate macro, uses them correctly instead of passing them as parameters makes for a difficult debug job when something goes odd.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 14:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/587540#M167832</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-10T14:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Code - Annual Rate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/588624#M168250</link>
      <description>&lt;P&gt;Thank you so much for the input- this is what i'm looking for. However, i get the following error when I run it. Any thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: The index variable in the %DO YEAR loop has taken on an invalid or missing value. The&lt;BR /&gt;macro will stop executing.&lt;BR /&gt;ERROR: The macro LOOP will stop executing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 18:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/588624#M168250</guid>
      <dc:creator>hlovejoy</dc:creator>
      <dc:date>2019-09-13T18:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Code - Annual Rate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/588632#M168255</link>
      <description>&lt;P&gt;OK, I played with that a little more, and it is working now! I just had to rename the variable "year1". THANK YOU!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One small thing - In the output, it is giving the correct year in the description above the table, but not IN the table. In the table it gives the variable name. Thoughts on that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Title:&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;TABLE border="0" cellspacing="1" cellpadding="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;' X Deaths', 'Race1, NW Region, Both Sex, All Ages', '&lt;FONT color="#FF0000"&gt;2016&lt;/FONT&gt;'&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;Table:&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;X Deaths&lt;/TD&gt;&lt;TD&gt;Race1, NW Region, Both Sex, All Ages&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;&amp;amp;year1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;56&lt;/TD&gt;&lt;TD&gt;291020&lt;/TD&gt;&lt;TD&gt;21.0327&lt;/TD&gt;&lt;TD&gt;15.7465&lt;/TD&gt;&lt;TD&gt;28.4176&lt;/TD&gt;&lt;TD&gt;5.28622&lt;/TD&gt;&lt;TD&gt;7.38494&lt;/TD&gt;&lt;TD&gt;291020&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;DIV class="branch"&gt;&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="branch"&gt;&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 13 Sep 2019 19:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/588632#M168255</guid>
      <dc:creator>hlovejoy</dc:creator>
      <dc:date>2019-09-13T19:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Code - Annual Rate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/588638#M168258</link>
      <description>&lt;P&gt;OK I figured that out too &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thank you so much ChrisNZ!&lt;BR /&gt;&lt;BR /&gt;I had to change it to double quotes " " instead of single quotes ' '. Which you totally had in your example buy I overlooked.&lt;BR /&gt;&lt;BR /&gt;%let time = "&amp;amp;year1";&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 19:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-Code-Annual-Rate/m-p/588638#M168258</guid>
      <dc:creator>hlovejoy</dc:creator>
      <dc:date>2019-09-13T19:11:42Z</dc:date>
    </item>
  </channel>
</rss>

