<?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 I use a macro to iteratively sum over different rows? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-I-use-a-macro-to-iteratively-sum-over-different-rows/m-p/468620#M119727</link>
    <description>&lt;P&gt;Sorry your post is very hard to follow.&amp;nbsp; Post test data in the form of a datastep:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We only need a few rows that we can run and then have something to code against.&amp;nbsp; Then show what the output should look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I will say off the bat is this, Macro is&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;never needed&lt;/STRONG&gt;&lt;/U&gt;.&amp;nbsp; Almost all the macro coding I see can be replaced by simply understanding the data and how to model it correctly.&amp;nbsp; It sounds in this instance, you will be able to do what you want by either using retained variables, or by using proc summary or one of the procedures designed for the purpose, but without some clear example its hard to say.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jun 2018 08:37:54 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-06-08T08:37:54Z</dc:date>
    <item>
      <title>How to I use a macro to iteratively sum over different rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-I-use-a-macro-to-iteratively-sum-over-different-rows/m-p/468613#M119722</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have the following dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var 1 var2 var3 var4&lt;/P&gt;&lt;P&gt;region 1 2000 num1 num2&lt;/P&gt;&lt;P&gt;region1 2001 num3 num4&lt;/P&gt;&lt;P&gt;region1 32002 num5 num6&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;region1 2018 num19 num20&lt;/P&gt;&lt;P&gt;region2 2000 num21 num22&lt;/P&gt;&lt;P&gt;region2 ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regionn...&lt;/P&gt;&lt;P&gt;I need to create a new variable for each region for each year which computes the sum of var3 for year i + var4 for year (i+1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I have 100 regions and periods, I want a macro...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to create dummy variables for each year but I don't know how to invoke the dummy for year(i+1)&lt;/P&gt;&lt;P&gt;and I don't know what to do with my dummies...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro EWD;&lt;BR /&gt;%DO i=1950 %TO 2016;&lt;BR /&gt;%put bin%eval(&amp;amp;i+1);&lt;BR /&gt;sum=var3*bin&amp;amp;i+var4*bin%eval(&amp;amp;i+1));&lt;BR /&gt;%end;&lt;BR /&gt;%mend EWD_2;&lt;BR /&gt;&lt;BR /&gt;data new;&lt;BR /&gt;set essi;&lt;BR /&gt;%EWD_2;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 08:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-I-use-a-macro-to-iteratively-sum-over-different-rows/m-p/468613#M119722</guid>
      <dc:creator>CarolineDP</dc:creator>
      <dc:date>2018-06-08T08:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to I use a macro to iteratively sum over different rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-I-use-a-macro-to-iteratively-sum-over-different-rows/m-p/468620#M119727</link>
      <description>&lt;P&gt;Sorry your post is very hard to follow.&amp;nbsp; Post test data in the form of a datastep:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We only need a few rows that we can run and then have something to code against.&amp;nbsp; Then show what the output should look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I will say off the bat is this, Macro is&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;never needed&lt;/STRONG&gt;&lt;/U&gt;.&amp;nbsp; Almost all the macro coding I see can be replaced by simply understanding the data and how to model it correctly.&amp;nbsp; It sounds in this instance, you will be able to do what you want by either using retained variables, or by using proc summary or one of the procedures designed for the purpose, but without some clear example its hard to say.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 08:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-I-use-a-macro-to-iteratively-sum-over-different-rows/m-p/468620#M119727</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-08T08:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to I use a macro to iteratively sum over different rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-I-use-a-macro-to-iteratively-sum-over-different-rows/m-p/468622#M119728</link>
      <description>&lt;P&gt;You don't need a macro at all. Macros create dynamic code and are not for handling data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either sort by region and descending year, and use the lag() function, or merge the dataset to itself with firstobs=2, thereby creating a lookahead.&lt;/P&gt;
&lt;P&gt;For code, please post data in a datastep; see my footnotes for help.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 08:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-I-use-a-macro-to-iteratively-sum-over-different-rows/m-p/468622#M119728</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-08T08:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to I use a macro to iteratively sum over different rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-I-use-a-macro-to-iteratively-sum-over-different-rows/m-p/468664#M119747</link>
      <description>&lt;P&gt;Using the lag function was enough! Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 12:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-I-use-a-macro-to-iteratively-sum-over-different-rows/m-p/468664#M119747</guid>
      <dc:creator>CarolineDP</dc:creator>
      <dc:date>2018-06-08T12:26:25Z</dc:date>
    </item>
  </channel>
</rss>

