<?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: Lag in Data Loop in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Lag-in-Data-Loop/m-p/586829#M14591</link>
    <description>Thank you so much! this works perfectly!!</description>
    <pubDate>Fri, 06 Sep 2019 17:48:22 GMT</pubDate>
    <dc:creator>Will_FBB</dc:creator>
    <dc:date>2019-09-06T17:48:22Z</dc:date>
    <item>
      <title>Lag in Data Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lag-in-Data-Loop/m-p/586800#M14574</link>
      <description>&lt;P&gt;How do I calculate y so the first ID will be equal to x, while the subsequent y in Month 2 - 10 will be previous y - previous a - previous b - previous c for each ID?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure if lag function is the best solution for this, it does not calculate the way I wanted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test;&lt;BR /&gt;set test_data end=eof;&lt;BR /&gt;by ID;&lt;/P&gt;&lt;P&gt;do _n_=1 until (eof);&lt;BR /&gt;if first.ID then y=x;&lt;BR /&gt;y+lag(y)-lag(a)-lag(b)-lag(c);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;attach shows finished table that I want (before and after)&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2019 16:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lag-in-Data-Loop/m-p/586800#M14574</guid>
      <dc:creator>Will_FBB</dc:creator>
      <dc:date>2019-09-06T16:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Lag in Data Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lag-in-Data-Loop/m-p/586827#M14590</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/79424"&gt;@Will_FBB&lt;/a&gt;&amp;nbsp; See if this helps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $	Month	(x	a	b	c) (:comma10.);
cards;
A	1	 12,810 	 . 	 . 	 . 
A	2	 . 	 50 	 . 	 . 
A	3	 . 	 . 	 50 	 . 
A	4	 . 	 . 	 . 	 50 
A	5	 . 	 . 	 . 	 . 
A	6	 . 	 . 	 . 	 2,020 
A	7	 . 	 . 	 . 	 2,000 
A	8	 . 	 . 	 . 	 29 
A	9	 . 	 . 	 . 	 300 
A	10	 . 	 . 	 . 	 . 
B	1	 26,121 	 . 	 . 	 . 
B	2	 . 	 1,000 	 . 	 . 
B	3	 . 	 . 	 . 	 . 
B	4	 . 	 . 	 600 	 2,035 
B	5	 . 	 . 	 . 	 . 
B	6	 . 	 500 	 . 	 . 
B	7	 . 	 . 	 . 	 . 
B	8	 . 	 . 	 . 	 533 
B	9	 . 	 . 	 . 	 484 
B	10	 . 	 . 	 . 	 . 
;



data want;
 do until(last.id);
  set have;
  by id;
  array t(*) a--c;
  array u(3) _temporary_ ;
  retain _i _i1;
  if _n_=1 then do;
  _i=addrlong(t(1));
  _i1=addrlong(u(1));
  end;
  if first.id then y=x;
  else if n(of u(*))&amp;gt;0 then y+ (-sum(of u(*)));
  output;
  call missing(of u(*));
  call pokelong(peekclong(_i,dim(t)*8),_i1,dim(t)*8);
 end;
 call missing(y,of u(*));
 drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Sep 2019 17:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lag-in-Data-Loop/m-p/586827#M14590</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-06T17:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: Lag in Data Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lag-in-Data-Loop/m-p/586829#M14591</link>
      <description>Thank you so much! this works perfectly!!</description>
      <pubDate>Fri, 06 Sep 2019 17:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lag-in-Data-Loop/m-p/586829#M14591</guid>
      <dc:creator>Will_FBB</dc:creator>
      <dc:date>2019-09-06T17:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Lag in Data Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lag-in-Data-Loop/m-p/586840#M14593</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/79424"&gt;@Will_FBB&lt;/a&gt;&amp;nbsp; I think i overlooked something and unnecessarily complicated the previous. Here is a simple one&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input ID $	Month	(x	a	b	c) (:comma10.);
cards;
A	1	 12,810 	 . 	 . 	 . 
A	2	 . 	 50 	 . 	 . 
A	3	 . 	 . 	 50 	 . 
A	4	 . 	 . 	 . 	 50 
A	5	 . 	 . 	 . 	 . 
A	6	 . 	 . 	 . 	 2,020 
A	7	 . 	 . 	 . 	 2,000 
A	8	 . 	 . 	 . 	 29 
A	9	 . 	 . 	 . 	 300 
A	10	 . 	 . 	 . 	 . 
B	1	 26,121 	 . 	 . 	 . 
B	2	 . 	 1,000 	 . 	 . 
B	3	 . 	 . 	 . 	 . 
B	4	 . 	 . 	 600 	 2,035 
B	5	 . 	 . 	 . 	 . 
B	6	 . 	 500 	 . 	 . 
B	7	 . 	 . 	 . 	 . 
B	8	 . 	 . 	 . 	 533 
B	9	 . 	 . 	 . 	 484 
B	10	 . 	 . 	 . 	 . 
;


data want;
 do until(last.id);
  set have;
  by id;
  array t(*) a--c;
  if first.id then y=x;
  else if s&amp;gt;. then y+(-s);
  output;
  call missing(s);
  if n(of t(*))&amp;gt;0 then s=sum(of t(*));
 end;
 call missing(y);
 drop s;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please accept my apology&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2019 18:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lag-in-Data-Loop/m-p/586840#M14593</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-06T18:35:08Z</dc:date>
    </item>
  </channel>
</rss>

