<?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 How to perform the rolling sum without missing (SAS UE)? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-the-rolling-sum-without-missing-SAS-UE/m-p/602495#M174459</link>
    <description>&lt;P&gt;So I am trying to do the rolling sum (5 points) in SAS UE adding lags. I also want to get rid of missings, but they are still generated. What is wrong?&lt;/P&gt;&lt;P&gt;I tried doing if statements separately but didn't work...&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data SUM;&lt;BR /&gt;set work.IMPORT;&lt;BR /&gt;rollingsum = y+lag1(y)+lag2(y)+lag3(y)+lag4(y);&lt;BR /&gt;if x=-10 then rollingsum = y;&lt;BR /&gt;if x=(-9.9) then rollingsum = y+lag1(y);&lt;BR /&gt;if x=(-9.8) then rollingsum = y+lag1(y)+lag2(y);&lt;BR /&gt;if x=(-9.7) then rollingsum = y+lag1(y)+lag2(y)+lag3(y);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;obs x y rollingsum&lt;BR /&gt;1 -10 0.5440211109 0.5440211109&lt;BR /&gt;2 -9.9 0.4575358938 .&lt;BR /&gt;3 -9.8 0.3664791293 .&lt;BR /&gt;4 -9.7 0.2717606264 .&lt;BR /&gt;5 -9.6 0.1743267812 1.8141235416&lt;BR /&gt;6 -9.5 0.0751511205 1.3452535511&lt;BR /&gt;7 -9.4 -0.024775425 0.8629422319&lt;BR /&gt;8 -9.3 -0.124454424 0.3720086791&lt;BR /&gt;9 -9.2 -0.222889914 -0.122641861&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I want to have&lt;/P&gt;&lt;P&gt;obs x y rollingsum&lt;BR /&gt;1 -10 0.5440211109 0.5440211109&lt;BR /&gt;2 -9.9 0.4575358938 0.5440211109 + 0.4575358938&lt;BR /&gt;3 -9.8 0.3664791293 0.5440211109 + 0.4575358938 + 0.3664791293&lt;BR /&gt;4 -9.7 0.2717606264 ...+ 0.2717606264&lt;BR /&gt;5 -9.6 0.1743267812 1.8141235416&lt;BR /&gt;6 -9.5 0.0751511205 1.3452535511&lt;BR /&gt;7 -9.4 -0.024775425 0.8629422319&lt;BR /&gt;8 -9.3 -0.124454424 0.3720086791&lt;BR /&gt;9 -9.2 -0.222889914 -0.122641861&lt;/P&gt;</description>
    <pubDate>Thu, 07 Nov 2019 17:14:06 GMT</pubDate>
    <dc:creator>likich</dc:creator>
    <dc:date>2019-11-07T17:14:06Z</dc:date>
    <item>
      <title>How to perform the rolling sum without missing (SAS UE)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-the-rolling-sum-without-missing-SAS-UE/m-p/602495#M174459</link>
      <description>&lt;P&gt;So I am trying to do the rolling sum (5 points) in SAS UE adding lags. I also want to get rid of missings, but they are still generated. What is wrong?&lt;/P&gt;&lt;P&gt;I tried doing if statements separately but didn't work...&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data SUM;&lt;BR /&gt;set work.IMPORT;&lt;BR /&gt;rollingsum = y+lag1(y)+lag2(y)+lag3(y)+lag4(y);&lt;BR /&gt;if x=-10 then rollingsum = y;&lt;BR /&gt;if x=(-9.9) then rollingsum = y+lag1(y);&lt;BR /&gt;if x=(-9.8) then rollingsum = y+lag1(y)+lag2(y);&lt;BR /&gt;if x=(-9.7) then rollingsum = y+lag1(y)+lag2(y)+lag3(y);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;obs x y rollingsum&lt;BR /&gt;1 -10 0.5440211109 0.5440211109&lt;BR /&gt;2 -9.9 0.4575358938 .&lt;BR /&gt;3 -9.8 0.3664791293 .&lt;BR /&gt;4 -9.7 0.2717606264 .&lt;BR /&gt;5 -9.6 0.1743267812 1.8141235416&lt;BR /&gt;6 -9.5 0.0751511205 1.3452535511&lt;BR /&gt;7 -9.4 -0.024775425 0.8629422319&lt;BR /&gt;8 -9.3 -0.124454424 0.3720086791&lt;BR /&gt;9 -9.2 -0.222889914 -0.122641861&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I want to have&lt;/P&gt;&lt;P&gt;obs x y rollingsum&lt;BR /&gt;1 -10 0.5440211109 0.5440211109&lt;BR /&gt;2 -9.9 0.4575358938 0.5440211109 + 0.4575358938&lt;BR /&gt;3 -9.8 0.3664791293 0.5440211109 + 0.4575358938 + 0.3664791293&lt;BR /&gt;4 -9.7 0.2717606264 ...+ 0.2717606264&lt;BR /&gt;5 -9.6 0.1743267812 1.8141235416&lt;BR /&gt;6 -9.5 0.0751511205 1.3452535511&lt;BR /&gt;7 -9.4 -0.024775425 0.8629422319&lt;BR /&gt;8 -9.3 -0.124454424 0.3720086791&lt;BR /&gt;9 -9.2 -0.222889914 -0.122641861&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 17:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-the-rolling-sum-without-missing-SAS-UE/m-p/602495#M174459</guid>
      <dc:creator>likich</dc:creator>
      <dc:date>2019-11-07T17:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform the rolling sum without missing (SAS UE)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-the-rolling-sum-without-missing-SAS-UE/m-p/602615#M174483</link>
      <description>&lt;P&gt;Use the SUM function instead of +. When you use the plus sign and any of the values are missing the result will be missing.&lt;/P&gt;
&lt;P&gt;However if you use&lt;/P&gt;
&lt;PRE&gt;if x=(-9.7) then rollingsum = sum (y,lag1(y),lag2(y),lag3(y));&lt;/PRE&gt;
&lt;P&gt;that doesn't happen.&lt;/P&gt;
&lt;P&gt;However you will run into a classic issue about use of LAG with IF. The lag function retains separate queues.&lt;/P&gt;
&lt;P&gt;You would actually do better with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data SUM;
   set work.IMPORT;
   ly1 = lag1(y);
   ly2 = lag2(y);
   ly3 = lag3(y);
   ly4 = lag4(y);

   rollingsum = sum(y, ly1, ly2, ly3, lyr);
   if x=-10 then rollingsum = y;
   if x=(-9.9) then rollingsum = sum(y, ly1);
   if x=(-9.8) then rollingsum = sum(y, ly1, ly2);
   if x=(-9.7) then rollingsum = sum(y, ly1, ly2, ly3);
   drop ly1 - ly4;
run;&lt;/PRE&gt;
&lt;P&gt;You could run that code without the drop statement to see if the proper values of y are being used.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 20:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-the-rolling-sum-without-missing-SAS-UE/m-p/602615#M174483</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-07T20:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform the rolling sum without missing (SAS UE)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-the-rolling-sum-without-missing-SAS-UE/m-p/602627#M174485</link>
      <description>&lt;P&gt;Set the missings to zero, and then when you do a sum and add zero into the sum ... well, you know ...&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 21:39:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-the-rolling-sum-without-missing-SAS-UE/m-p/602627#M174485</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-07T21:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform the rolling sum without missing (SAS UE)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-the-rolling-sum-without-missing-SAS-UE/m-p/602635#M174488</link>
      <description>It is brilliant! Thank you so much!</description>
      <pubDate>Thu, 07 Nov 2019 21:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-the-rolling-sum-without-missing-SAS-UE/m-p/602635#M174488</guid>
      <dc:creator>likich</dc:creator>
      <dc:date>2019-11-07T21:45:04Z</dc:date>
    </item>
  </channel>
</rss>

