<?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: Calculation  between rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787217#M251491</link>
    <description>&lt;P&gt;This sounds a lot like carrying the last observation forward. It doesn't follow your request parameters, but it gets what you want, I think.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input ID time Y;
cards;
111 1 8
111 2 .
111 3 7
111 4 7
111 5 6
111 6 8
222 1 4
222 2 5
222 3 4
222 4 6
222 5 6
222 6 7
;
Run;

data want;
	set have;
	by id;
	retain y2;
		if first.id then call missing(y2);
		if not missing(y) then y2 = y;
run;

/* Removing the original variable for cleaner output (not shown) */

data want (drop = y rename = (y2 = y));
	set have;
	by id;
	retain y2;
		if first.id then call missing(y2);
		if not missing(y) then y2 = y;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;ID time Y y2 
111 1 8 8 
111 2 . 8 
111 3 7 7 
111 4 7 7 
111 5 6 6 
111 6 8 8 
222 1 4 4 
222 2 5 5 
222 3 4 4 
222 4 6 6 
222 5 6 6 
222 6 7 7 
&lt;/PRE&gt;</description>
    <pubDate>Thu, 23 Dec 2021 10:43:19 GMT</pubDate>
    <dc:creator>maguiremq</dc:creator>
    <dc:date>2021-12-23T10:43:19Z</dc:date>
    <item>
      <title>Calculation  between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787203#M251480</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to re-calculate column Y with the following rule:&lt;/P&gt;
&lt;P&gt;The calculation is done per customer ID.&lt;/P&gt;
&lt;P&gt;IF Y in time 1 is not null and Y in time 2 is null then Y in time 2 will be equal to Y in time 1.&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input ID time Y;
cards;
111 1 8
111 2 .
111 3 7
111 4 7
111 5 6
111 6 8
222 1 4
222 2 5
222 3 4
222 4 6
222 5 6
222 6 7
;
Run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Dec 2021 07:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787203#M251480</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-23T07:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation  between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787204#M251481</link>
      <description>&lt;P&gt;What does your desired result look like then?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 07:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787204#M251481</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-12-23T07:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation  between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787217#M251491</link>
      <description>&lt;P&gt;This sounds a lot like carrying the last observation forward. It doesn't follow your request parameters, but it gets what you want, I think.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input ID time Y;
cards;
111 1 8
111 2 .
111 3 7
111 4 7
111 5 6
111 6 8
222 1 4
222 2 5
222 3 4
222 4 6
222 5 6
222 6 7
;
Run;

data want;
	set have;
	by id;
	retain y2;
		if first.id then call missing(y2);
		if not missing(y) then y2 = y;
run;

/* Removing the original variable for cleaner output (not shown) */

data want (drop = y rename = (y2 = y));
	set have;
	by id;
	retain y2;
		if first.id then call missing(y2);
		if not missing(y) then y2 = y;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;ID time Y y2 
111 1 8 8 
111 2 . 8 
111 3 7 7 
111 4 7 7 
111 5 6 6 
111 6 8 8 
222 1 4 4 
222 2 5 5 
222 3 4 4 
222 4 6 6 
222 5 6 6 
222 6 7 7 
&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Dec 2021 10:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787217#M251491</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-12-23T10:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation  between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787223#M251494</link>
      <description>&lt;P&gt;The acronym for this is LOCF (Last Observation Carry Forward).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by id;
retain _y;
if first.id then _y = y;
if missing(y)
then y = _y;
else _y = y;
drop _y;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Dec 2021 11:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787223#M251494</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-12-23T11:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation  between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787249#M251515</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	update have(obs=0) have;
	by id;
	output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Dec 2021 16:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787249#M251515</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2021-12-23T16:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation  between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787255#M251519</link>
      <description>111 1 8&lt;BR /&gt;111 2 8&lt;BR /&gt;111 3 7&lt;BR /&gt;111 4 7&lt;BR /&gt;111 5 6&lt;BR /&gt;111 6 8&lt;BR /&gt;222 1 4&lt;BR /&gt;222 2 5&lt;BR /&gt;222 3 4&lt;BR /&gt;222 4 6&lt;BR /&gt;222 5 6&lt;BR /&gt;222 6 7</description>
      <pubDate>Thu, 23 Dec 2021 16:30:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787255#M251519</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-23T16:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation  between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787257#M251521</link>
      <description>May you please explain what this code is doing?</description>
      <pubDate>Thu, 23 Dec 2021 16:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787257#M251521</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-23T16:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation  between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787258#M251522</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I think that you didn't relate your code to the request of filling null value only in second row per cudtomer ID.It means that if 3rd,4th ,5th,6th rows are with null Y value then no need to change it.&lt;/P&gt;
&lt;P&gt;The only potetnail change is in 2nd row per customer ID&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 16:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-between-rows/m-p/787258#M251522</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-12-23T16:37:11Z</dc:date>
    </item>
  </channel>
</rss>

