<?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: Computed column calculation with previous row values in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583910#M14041</link>
    <description>&lt;P&gt;Here is one way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Cmonth $ count;
datalines;
Jan 3
Feb 1
Mar 3
Apr 5
May 6
Jun 7
Jul 2
Aug 1
Sep 3
Oct 5
Nov 6
Dec 8
;

data want(drop=obs);
    array lag[0:2] _temporary_;
    do obs=1 by 1 until (lr);
        set have end=lr;
        lag[mod(obs, 3)]=count;
        sum=sum(of lag[*]);
        output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 26 Aug 2019 13:52:49 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-08-26T13:52:49Z</dc:date>
    <item>
      <title>Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583907#M14040</link>
      <description>&lt;P&gt;hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;im trying to implement an easy excel formula to a SAS computed column. Can someone help me,&lt;/P&gt;&lt;P&gt;here is the formula with result shown in column C excel sheet screenshot, i would like to have &lt;STRONG&gt;Column C&lt;/STRONG&gt;&amp;nbsp;values as SAS computed Column&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capturse.JPG" style="width: 150px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32035iA97783592AC57AFC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capturse.JPG" alt="Capturse.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 510px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32034iF4DCB22C8D607622/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 13:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583907#M14040</guid>
      <dc:creator>VimalManavalan</dc:creator>
      <dc:date>2019-08-26T13:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583910#M14041</link>
      <description>&lt;P&gt;Here is one way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Cmonth $ count;
datalines;
Jan 3
Feb 1
Mar 3
Apr 5
May 6
Jun 7
Jul 2
Aug 1
Sep 3
Oct 5
Nov 6
Dec 8
;

data want(drop=obs);
    array lag[0:2] _temporary_;
    do obs=1 by 1 until (lr);
        set have end=lr;
        lag[mod(obs, 3)]=count;
        sum=sum(of lag[*]);
        output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Aug 2019 13:52:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583910#M14041</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-26T13:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583916#M14042</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let window=3;
data want;
 do _n_=1 to &amp;amp;window until(z);
  set have end=z;
  array t(&amp;amp;window) _temporary_;
  _iorc_+1;
  t(_n_)=count;
  if _iorc_&amp;gt;=&amp;amp;window then want=sum(of t(*));
  output;
 end;
run;
  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Aug 2019 14:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583916#M14042</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-26T14:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583919#M14043</link>
      <description>&lt;P&gt;Will it be possible to create a SAS computed&amp;nbsp; column for column C instead of running program&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 14:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583919#M14043</guid>
      <dc:creator>VimalManavalan</dc:creator>
      <dc:date>2019-08-26T14:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583921#M14044</link>
      <description>&lt;P&gt;Will it be possible to create a SAS computed&amp;nbsp; column for column C instead of running program?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 14:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583921#M14044</guid>
      <dc:creator>VimalManavalan</dc:creator>
      <dc:date>2019-08-26T14:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583922#M14045</link>
      <description>&lt;P&gt;Hmm what do you mean by that?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 14:20:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583922#M14045</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-26T14:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583928#M14046</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS enterprise guide has an option to create computed column using query builder, which is an easy way to create columns using SAS functons. screnshot attached.&lt;/P&gt;&lt;P&gt;it would be really great we can manage it via SAS computed column. is it possible?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dd.JPG" style="width: 450px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32037iDEC0A28EAFBD30EF/image-size/large?v=v2&amp;amp;px=999" role="button" title="dd.JPG" alt="dd.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 14:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583928#M14046</guid>
      <dc:creator>VimalManavalan</dc:creator>
      <dc:date>2019-08-26T14:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583931#M14047</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/280251"&gt;@VimalManavalan&lt;/a&gt;&amp;nbsp; Oh well, I haven't used much of the point-n-click SAS EG lately and you are likely to know more about it. For all I know, that generates and embedded SQL query. So if you want a SQL approach for the same, I can give you SQL code. However, you would still need a numeric Month or a monotonic() to get a sequence of months to get the &lt;EM&gt;&lt;STRONG&gt;window period.&lt;/STRONG&gt; So, are you after the SQL approach?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 14:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583931#M14047</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-26T14:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583933#M14048</link>
      <description>&lt;P&gt;I'm not much of an Enterprise Guide user. But I doubt that you can implement this logic with a point-and-click tool&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 14:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583933#M14048</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-26T14:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583937#M14049</link>
      <description>&lt;P&gt;If possible Please share SQL code, I will try to convert to SAS computed column once I&amp;nbsp; understand the logic thanks&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 14:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583937#M14049</guid>
      <dc:creator>VimalManavalan</dc:creator>
      <dc:date>2019-08-26T14:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583945#M14052</link>
      <description>&lt;P&gt;Okay &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/280251"&gt;@VimalManavalan&lt;/a&gt;&amp;nbsp;, if you can make month 1-12 in the form of numbers, addressing a window period is easy --&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here 3 is the window period&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.*,ifn(count(*)&amp;gt;=3,sum(b.count),.) as want
from have a left join have b
on a.month-2&amp;lt;=b.month&amp;lt;=a.month
group by a.month,a.count
order by a.month;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Else you may have create a sequence with monotonic() function in an&lt;EM&gt; in-line view&lt;/EM&gt; and then do the same&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want(drop=m) as
select a.*,ifn(count(*)&amp;gt;=3,sum(b.count),.) as want
from (select *,monotonic() as m from have) a left join (select *,monotonic() as m from have) b
on a.m-2&amp;lt;=b.m&amp;lt;=a.m
group by a.m,a.month,a.count
order by a.m;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 15:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583945#M14052</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-26T15:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583952#M14055</link>
      <description>&lt;P&gt;Check if you have a license for SAS ETS. If you do, use PROC TIMESERIES or one of the time series data prep tasks to do this instead of manually coding it yourself. That will account for missing months for example which you won't catch with a data step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can check what you have licensed in SAS using:&lt;BR /&gt;proc setinit; run;&lt;BR /&gt;And what's installed on your system using:&lt;BR /&gt;proc product_status; run;&lt;BR /&gt;The output will be in the log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/280251"&gt;@VimalManavalan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;im trying to implement an easy excel formula to a SAS computed column. Can someone help me,&lt;/P&gt;
&lt;P&gt;here is the formula with result shown in column C excel sheet screenshot, i would like to have &lt;STRONG&gt;Column C&lt;/STRONG&gt;&amp;nbsp;values as SAS computed Column&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capturse.JPG" style="width: 150px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32035iA97783592AC57AFC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capturse.JPG" alt="Capturse.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 510px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32034iF4DCB22C8D607622/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 15:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/583952#M14055</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-26T15:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/788287#M32366</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
set have;
format date date9.;
date=input(cats('01',cmonth,'2021'),date9.);
run;

proc expand data=have2 method=none out=want;
id date;
convert count=sum_lag3 / tout=(movsum 3);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jan 2022 14:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/788287#M32366</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-01-04T14:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Computed column calculation with previous row values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/788290#M32368</link>
      <description>&lt;P&gt;I like it but I don't fully understand.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you be so kind to explain?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand all pieces of your code but I do not see how they unfold as a whole.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've problems in coming behind the logic of a set statenent within the do loop.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 14:55:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computed-column-calculation-with-previous-row-values/m-p/788290#M32368</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-01-04T14:55:41Z</dc:date>
    </item>
  </channel>
</rss>

