<?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 A Lag Rolling &amp;quot;Product&amp;quot;? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162114#M42154</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much. Works Perfectly. Appreciate everyone else's efforts as well. Great community here.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 01 Jul 2014 16:55:45 GMT</pubDate>
    <dc:creator>Buzzshot43</dc:creator>
    <dc:date>2014-07-01T16:55:45Z</dc:date>
    <item>
      <title>How to Create A Lag Rolling "Product"?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162104#M42144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to make a column that will be added to an existing data set. I need it to Multiply its number by the 6 previous entries (including its own for a total of 7) but only if the previous entries are under the same categories:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have looked up Rolling lag "by group" but i have had no luck creating my result column.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="248" style="border: 1px solid #000000; width: 489px; height: 248px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Category A&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Category B&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Numbers &lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;**Column I am looking to Add**&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;3&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;3&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;72&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;144&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;288&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;576&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;288&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All help is appreciated. Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 13:30:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162104#M42144</guid>
      <dc:creator>Buzzshot43</dc:creator>
      <dc:date>2014-07-01T13:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create A Lag Rolling "Product"?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162105#M42145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could use retain:&lt;/P&gt;&lt;P&gt;data have (drop=lsta lstb lstnum);&lt;BR /&gt;&amp;nbsp; attrib CatA catB format=$1. Numbers format=best.;&lt;BR /&gt;&amp;nbsp; infile cards;&lt;BR /&gt;&amp;nbsp; input cata $ catb $ numbers;&lt;BR /&gt;cards;&lt;BR /&gt;A B 2&lt;BR /&gt;A B 3&lt;BR /&gt;A B 3&lt;BR /&gt;A B 4&lt;BR /&gt;B B 2&lt;BR /&gt;B B 3&lt;BR /&gt;B A 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;&amp;nbsp; set have;&lt;BR /&gt;&amp;nbsp; attrib result format=best.;&lt;BR /&gt;&amp;nbsp; retain lsta lstb lstnum;&lt;BR /&gt;&amp;nbsp; if _n_=1 or lsta ne cata or lstb ne catb then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lsta=cata;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstb=catb;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstnum=numbers;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result=numbers;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; else do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result=lstnum * numbers;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstnum=result;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 13:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162105#M42145</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-07-01T13:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create A Lag Rolling "Product"?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162106#M42146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your swift response. A few things,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) It ended up creating new columns for result, CatA, CatB, 1st number and result, is there a way to avoid this and just have the result be the remaining column?&lt;/P&gt;&lt;P&gt;2) I forgot to mention this, but if there is nothing in the cells, then to treat the value in them as "1" ..... IE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&amp;nbsp; B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&amp;nbsp; B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&amp;nbsp; B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;6&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 14:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162106#M42146</guid>
      <dc:creator>Buzzshot43</dc:creator>
      <dc:date>2014-07-01T14:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create A Lag Rolling "Product"?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162107#M42147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can simplify some of the logic using BY group processing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;by category_a category_b notsorted;&lt;/P&gt;&lt;P&gt;if numbers=. then factor=1;&lt;/P&gt;&lt;P&gt;else factor=numbers;&lt;/P&gt;&lt;P&gt;drop factor;&lt;/P&gt;&lt;P&gt;if first.category_b then new_column=factor;&lt;/P&gt;&lt;P&gt;else new_column = new_column * factor;&lt;/P&gt;&lt;P&gt;retain new_column;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 14:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162107#M42147</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-07-01T14:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create A Lag Rolling "Product"?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162108#M42148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yep, just modify as:&lt;/P&gt;&lt;P&gt;data want (drop=lsta lstb lstnum);&lt;BR /&gt;&amp;nbsp; set have;&lt;BR /&gt;&amp;nbsp; attrib result format=best.;&lt;BR /&gt;&amp;nbsp; retain lsta lstb lstnum;&lt;BR /&gt;&amp;nbsp; if _n_=1 or lsta ne cata or lstb ne catb then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lsta=cata;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstb=catb;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstnum=numbers;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result=numbers;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; else do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if numbers=. then result=lstnum;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else result=lstnum * numbers;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstnum=result;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 14:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162108#M42148</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-07-01T14:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create A Lag Rolling "Product"?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162109#M42149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The following code works even if you have more then 7 observations in one by group:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; attrib CatA catB format=$1. Numbers format=best.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile cards;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input cata $ catb $ numbers;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;A B 2&lt;/P&gt;&lt;P&gt;A B 3&lt;/P&gt;&lt;P&gt;A B 3&lt;/P&gt;&lt;P&gt;A B 4&lt;/P&gt;&lt;P&gt;A B 2&lt;/P&gt;&lt;P&gt;A B 2&lt;/P&gt;&lt;P&gt;A B 2&lt;/P&gt;&lt;P&gt;A B 1&lt;/P&gt;&lt;P&gt;B B 2&lt;/P&gt;&lt;P&gt;B B 3&lt;/P&gt;&lt;P&gt;B A 2&lt;/P&gt;&lt;P&gt;B A 4&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp; keep catA catB result Numbers;&amp;nbsp; by catA catB notsorted;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array lastNums[7] _temporary_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain pointer;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.catB then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to dim(lastNums);&lt;/P&gt;&lt;P&gt;&amp;nbsp; lastNums&lt;I&gt;=1;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; pointer=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; lastNums[pointer]=coalesce(numbers,1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; pointer=mod(pointer,dim(lastNums))+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; result=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to dim(lastNums);&lt;/P&gt;&lt;P&gt;&amp;nbsp; result=result*lastNums&lt;I&gt;;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Gergely Bathó - modified the keep statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 14:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162109#M42149</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2014-07-01T14:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create A Lag Rolling "Product"?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162110#M42150</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this !!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; y1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;input&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; cat_1 $ cat_2 $ numbers;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New';"&gt;A B 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New';"&gt;A B 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New';"&gt;A B 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New';"&gt;A B 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New';"&gt;A B 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New';"&gt;A B 2&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New';"&gt;A B 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New';"&gt;A B 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New';"&gt;B B 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New';"&gt;B B 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New';"&gt;B A 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New';"&gt;B A 4&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;sort&lt;/STRONG&gt; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;data&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;=y1;&lt;/SPAN&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;by&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; cat_1 cat_2;&lt;/SPAN&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; y2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; y1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;by&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; cat_1 cat_2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; first.cat_2=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;then&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;do&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;retain&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; x &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;x&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;=numbers-&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;end&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;x&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;=(numbers)*x;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 15:16:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162110#M42150</guid>
      <dc:creator>yeshwanth</dc:creator>
      <dc:date>2014-07-01T15:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create A Lag Rolling "Product"?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162111#M42151</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can this be applied to also the last 7 Numbers? Yours worked in the way I wanted to except the new column kept compounding as opposed to keep a "rolling" product of only the last 7 entries. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 15:32:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162111#M42151</guid>
      <dc:creator>Buzzshot43</dc:creator>
      <dc:date>2014-07-01T15:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create A Lag Rolling "Product"?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162112#M42152</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, I missed that part about the last 7 entries only.&amp;nbsp; Here's a modification:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;by category_a category_b notsorted;&lt;/P&gt;&lt;P&gt;if numbers=. then factor=1;&lt;/P&gt;&lt;P&gt;else factor=numbers;&lt;/P&gt;&lt;P&gt;drop factor;&lt;/P&gt;&lt;P&gt;back7 = lag7(factor);&lt;/P&gt;&lt;P&gt;if first.category_b then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; new_column=factor;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; counter = 1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;else do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; new_column = new_column * factor;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; counter + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if counter &amp;gt; 7 then new_column = new_column / back7;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;retain new_column;&lt;/P&gt;&lt;P&gt;drop back7;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 15:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162112#M42152</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-07-01T15:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create A Lag Rolling "Product"?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162113#M42153</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;BR /&gt; input cata $ catb $ numbers;&lt;BR /&gt;cards;&lt;BR /&gt;A B 2&lt;BR /&gt;A B 3&lt;BR /&gt;A B .&lt;BR /&gt;A B 4&lt;BR /&gt;B B 2&lt;BR /&gt;B B 3&lt;BR /&gt;B A 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;&amp;nbsp; set have;&lt;BR /&gt;&amp;nbsp; by cata;&lt;BR /&gt;&amp;nbsp; retain temp;&lt;BR /&gt;&amp;nbsp; if first.cata then add=numbers;&lt;BR /&gt;&amp;nbsp; else add=coalesce(numbers,1)*temp;&lt;BR /&gt;&amp;nbsp; temp=add;&lt;BR /&gt;&amp;nbsp; drop temp;&lt;BR /&gt;&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 15:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162113#M42153</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2014-07-01T15:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create A Lag Rolling "Product"?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162114#M42154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much. Works Perfectly. Appreciate everyone else's efforts as well. Great community here.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 16:55:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Create-A-Lag-Rolling-quot-Product-quot/m-p/162114#M42154</guid>
      <dc:creator>Buzzshot43</dc:creator>
      <dc:date>2014-07-01T16:55:45Z</dc:date>
    </item>
  </channel>
</rss>

