<?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: compute the mid-value of the value of two years in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697428#M213121</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp; Basically the POINT= directly reads an observation from a SAS dataset that is the value of the variable specified in the (POINT= variable) option. You&amp;nbsp;&lt;SPAN&gt;would have noticed, processing is required for only those records of a by group that is &lt;STRONG&gt;not&lt;/STRONG&gt; the 1st record. Therefore,&amp;nbsp;while processing these(&lt;EM&gt;2nd to last record of a by group&lt;/EM&gt;) records using&amp;nbsp;the LAG information, the original information that&amp;nbsp;was read into the PDV is &lt;STRONG&gt;&lt;EM&gt;lost&lt;/EM&gt;&lt;/STRONG&gt; for that particular record. Rather,&amp;nbsp;we&amp;nbsp;would only have the computed information. In order to fetch the original information&amp;nbsp;we need a&amp;nbsp;way to&lt;STRONG&gt;&lt;EM&gt; re-read&amp;nbsp;&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;the same record that gets our original information for these records viz. in your example 1998,2000,2002. I hope this makes sense?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps, the follo&lt;SPAN&gt;wing depiction&amp;nbsp;may clarify better-&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if not first.country then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&lt;FONT color="#000080"&gt;year=l_year+1;&amp;nbsp; /*This computation resets to computed value using lags, thus losing original record*/&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;&amp;nbsp;&amp;nbsp; cc=round(mean(l_cc,cc),.01);/*This computation resets to computed value using lags, thus losing original record*/&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#993300"&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;set table1 point=n;/*This computation resets to original value by re-reading the record the dataset again*/&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 08 Nov 2020 13:46:05 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-11-08T13:46:05Z</dc:date>
    <item>
      <title>compute the mid-value of the value of two years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697376#M213097</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to compute the mid-value of the value of two years.&lt;/P&gt;&lt;P&gt;For table 1,&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;country&lt;/TD&gt;&lt;TD&gt;year&lt;/TD&gt;&lt;TD&gt;CC&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;1996&lt;/TD&gt;&lt;TD&gt;-1.29&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;1998&lt;/TD&gt;&lt;TD&gt;-1.18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;-1.30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;2002&lt;/TD&gt;&lt;TD&gt;-1.26&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALBANIA&lt;/TD&gt;&lt;TD&gt;1996&lt;/TD&gt;&lt;TD&gt;-0.89&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALBANIA&lt;/TD&gt;&lt;TD&gt;1998&lt;/TD&gt;&lt;TD&gt;-1.03&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALBANIA&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;-0.86&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALBANIA&lt;/TD&gt;&lt;TD&gt;2002&lt;/TD&gt;&lt;TD&gt;-0.87&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;for each country, I have the value of 1996, 1998, 2000, 2002.&lt;/P&gt;&lt;P&gt;I am trying to get the value of 1997 by using the mid-value of 1996 and 1998, get the value of 1999 by using the mid-value of 1998 and 2000,&lt;/P&gt;&lt;P&gt;get the value of 2001 by using the mid-value of 2000 and 2001.&lt;/P&gt;&lt;P&gt;for example, the CC of&amp;nbsp;AFGHANISTAN in 1997 is expect to equal (-1.29+-1.18)/2 =-1.24&lt;/P&gt;&lt;P&gt;the final result of&amp;nbsp;AFGHANISTAN should look like below&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;country&lt;/TD&gt;&lt;TD&gt;year&lt;/TD&gt;&lt;TD&gt;CC&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;1996&lt;/TD&gt;&lt;TD&gt;-1.29&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;1997&lt;/TD&gt;&lt;TD&gt;-1.24&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;1998&lt;/TD&gt;&lt;TD&gt;-1.18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;1999&lt;/TD&gt;&lt;TD&gt;-1.24&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;-1.30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;-1.28&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;2002&lt;/TD&gt;&lt;TD&gt;-1.26&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please give me some suggestion about this?&lt;/P&gt;&lt;P&gt;thank in advance.&lt;/P&gt;&lt;PRE&gt;data table1;
	infile cards dsd  dlm=",";
	input
	country :$50.
	year :8.
	CC :8.
	;
	cards;
AFGHANISTAN,1996,-1.29
AFGHANISTAN,1998,-1.18
AFGHANISTAN,2000,-1.30
AFGHANISTAN,2002,-1.26
ALBANIA,1996,-0.89
ALBANIA,1998,-1.03
ALBANIA,2000,-0.86
ALBANIA,2002,-0.87
	;;;;
run;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Nov 2020 23:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697376#M213097</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2020-11-07T23:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: compute the mid-value of the value of two years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697378#M213099</link>
      <description>&lt;P&gt;Data step is pretty simple.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set table; 
by country year;
prev_value = lag(cc);
prev_year = lag(year);
if not first.country then do;
output;
year = year+1;
cc = mean(cc, prev_value);
if not last.country then output;
end;
*not sure if this is needed;
else output;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will want to sort afterwards, untested.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 23:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697378#M213099</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-11-07T23:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: compute the mid-value of the value of two years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697380#M213100</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I do not get the value of 1997.&lt;/P&gt;&lt;P&gt;Could you please have a look?&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;country&lt;/TD&gt;&lt;TD&gt;year&lt;/TD&gt;&lt;TD&gt;CC&lt;/TD&gt;&lt;TD&gt;prev_value&lt;/TD&gt;&lt;TD&gt;prev_year&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;1996&lt;/TD&gt;&lt;TD&gt;-1.29&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;1998&lt;/TD&gt;&lt;TD&gt;-1.18&lt;/TD&gt;&lt;TD&gt;-1.29&lt;/TD&gt;&lt;TD&gt;1996&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;1999&lt;/TD&gt;&lt;TD&gt;-1.235&lt;/TD&gt;&lt;TD&gt;-1.29&lt;/TD&gt;&lt;TD&gt;1996&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;-1.3&lt;/TD&gt;&lt;TD&gt;-1.18&lt;/TD&gt;&lt;TD&gt;1998&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;2001&lt;/TD&gt;&lt;TD&gt;-1.24&lt;/TD&gt;&lt;TD&gt;-1.18&lt;/TD&gt;&lt;TD&gt;1998&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AFGHANISTAN&lt;/TD&gt;&lt;TD&gt;2002&lt;/TD&gt;&lt;TD&gt;-1.26&lt;/TD&gt;&lt;TD&gt;-1.3&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALBANIA&lt;/TD&gt;&lt;TD&gt;1996&lt;/TD&gt;&lt;TD&gt;-0.89&lt;/TD&gt;&lt;TD&gt;-1.26&lt;/TD&gt;&lt;TD&gt;2002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALBANIA&lt;/TD&gt;&lt;TD&gt;1998&lt;/TD&gt;&lt;TD&gt;-1.03&lt;/TD&gt;&lt;TD&gt;-0.89&lt;/TD&gt;&lt;TD&gt;1996&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALBANIA&lt;/TD&gt;&lt;TD&gt;1999&lt;/TD&gt;&lt;TD&gt;-0.96&lt;/TD&gt;&lt;TD&gt;-0.89&lt;/TD&gt;&lt;TD&gt;1996&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALBANIA&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;-0.86&lt;/TD&gt;&lt;TD&gt;-1.03&lt;/TD&gt;&lt;TD&gt;1998&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALBANIA&lt;/TD&gt;&lt;TD&gt;2001&lt;/TD&gt;&lt;TD&gt;-0.945&lt;/TD&gt;&lt;TD&gt;-1.03&lt;/TD&gt;&lt;TD&gt;1998&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALBANIA&lt;/TD&gt;&lt;TD&gt;2002&lt;/TD&gt;&lt;TD&gt;-0.87&lt;/TD&gt;&lt;TD&gt;-0.86&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sat, 07 Nov 2020 23:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697380#M213100</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2020-11-07T23:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: compute the mid-value of the value of two years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697382#M213101</link>
      <description>Year should be Year - 1</description>
      <pubDate>Sun, 08 Nov 2020 00:30:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697382#M213101</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-11-08T00:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: compute the mid-value of the value of two years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697384#M213102</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp; Basically,- Lag, plug, re-read the record that's plugged using POINT=. That's just it&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
	infile cards dsd  dlm=",";
	input
	country :$50.
	year :8.
	CC :8.
	;
	cards;
AFGHANISTAN,1996,-1.29
AFGHANISTAN,1998,-1.18
AFGHANISTAN,2000,-1.30
AFGHANISTAN,2002,-1.26
ALBANIA,1996,-0.89
ALBANIA,1998,-1.03
ALBANIA,2000,-0.86
ALBANIA,2002,-0.87
	;;;;
run;


data want;
 do until(last.country);
  set table1 ;
  by country;
  n+1;
  l_cc = lag(cc);
  l_year = lag(year);
  if not first.country then do;
   year=l_year+1;
   cc=round(mean(l_cc,cc),.01);
   output;
   set table1 point=n;
   output;
  end;
  else output;
 end;
 drop l_:;
 format cc 8.2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Nov 2020 01:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697384#M213102</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-08T01:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: compute the mid-value of the value of two years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697393#M213104</link>
      <description>&lt;P&gt;You can interpolate with proc expand:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc expand data=table1 out=table2 factor=(2:1);
by country;
id year;
convert CC=CCC / method=join;
run;

proc print data=table2 noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 171px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51500i9D29F3758CC22A5F/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Nov 2020 04:03:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697393#M213104</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-11-08T04:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: compute the mid-value of the value of two years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697418#M213117</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May I ask what is the logic to use following code,&lt;/P&gt;&lt;PRE&gt;set table1 point=n;
   output;
  end;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I saw when I delete these code, I lose the observation of the year 1998, 2000 and 2002.&amp;nbsp;&lt;SPAN&gt;Point refers to a specific observation in a data set. but why it generates the obs of year 1998, 2000 and 2002 rather than the other year?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Could you please explain this for me?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Nov 2020 09:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697418#M213117</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2020-11-08T09:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: compute the mid-value of the value of two years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697419#M213118</link>
      <description>&lt;P&gt;My preferred method: do a look-ahead MERGE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
infile cards dsd dlm=",";
input
  country :$50.
  year :8.
  CC :8.
;
cards;
AFGHANISTAN,1996,-1.29
AFGHANISTAN,1998,-1.18
AFGHANISTAN,2000,-1.30
AFGHANISTAN,2002,-1.26
ALBANIA,1996,-0.89
ALBANIA,1998,-1.03
ALBANIA,2000,-0.86
ALBANIA,2002,-0.87
;
  
data want;
merge
  table1
  table1 (
    firstobs=2
    rename=(
      country=_country
      year=_year
      cc=_cc
    )
  )
;
output;
if country = _country
then do;
  cc = (cc + _cc) / 2;
  do year = year + 1 to _year - 1;
    output;
  end;
end;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Nov 2020 10:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697419#M213118</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-08T10:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: compute the mid-value of the value of two years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697420#M213119</link>
      <description>&lt;PRE&gt;data table1;
	infile cards dsd  dlm=",";
	input
	country :$50.
	year :8.
	CC :8.
	;
	cards;
AFGHANISTAN,1996,-1.29
AFGHANISTAN,1998,-1.18
AFGHANISTAN,2000,-1.30
AFGHANISTAN,2002,-1.26
ALBANIA,1996,-0.89
ALBANIA,1998,-1.03
ALBANIA,2000,-0.86
ALBANIA,2002,-0.87
	;;;;
run;
data want;
 merge table1 table1(firstobs=2 
 rename=(country=_country year=_year cc=_cc));
 output;
 if country=_country then do;
   do i=year+1 to _year-1;
    cc=(_cc+cc)/(_year-year); year=i;output;
   end;
 end;
 drop _: i ;
run;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Nov 2020 11:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697420#M213119</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-11-08T11:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: compute the mid-value of the value of two years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697428#M213121</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp; Basically the POINT= directly reads an observation from a SAS dataset that is the value of the variable specified in the (POINT= variable) option. You&amp;nbsp;&lt;SPAN&gt;would have noticed, processing is required for only those records of a by group that is &lt;STRONG&gt;not&lt;/STRONG&gt; the 1st record. Therefore,&amp;nbsp;while processing these(&lt;EM&gt;2nd to last record of a by group&lt;/EM&gt;) records using&amp;nbsp;the LAG information, the original information that&amp;nbsp;was read into the PDV is &lt;STRONG&gt;&lt;EM&gt;lost&lt;/EM&gt;&lt;/STRONG&gt; for that particular record. Rather,&amp;nbsp;we&amp;nbsp;would only have the computed information. In order to fetch the original information&amp;nbsp;we need a&amp;nbsp;way to&lt;STRONG&gt;&lt;EM&gt; re-read&amp;nbsp;&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;the same record that gets our original information for these records viz. in your example 1998,2000,2002. I hope this makes sense?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps, the follo&lt;SPAN&gt;wing depiction&amp;nbsp;may clarify better-&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if not first.country then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&lt;FONT color="#000080"&gt;year=l_year+1;&amp;nbsp; /*This computation resets to computed value using lags, thus losing original record*/&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;&amp;nbsp;&amp;nbsp; cc=round(mean(l_cc,cc),.01);/*This computation resets to computed value using lags, thus losing original record*/&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#993300"&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;set table1 point=n;/*This computation resets to original value by re-reading the record the dataset again*/&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Nov 2020 13:46:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697428#M213121</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-08T13:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: compute the mid-value of the value of two years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697455#M213136</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s idea of reading the input dataset only once. Here's another (similar) implementation of that idea:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_:);
set table1;
by country year;
_cc=round(mean(cc, lag(cc)), 1e-9);
if first.country then output;
else do;
  _c=cc; cc=_cc; year+-1; output;
  cc=_c;         year+ 1; output;
end;
format cc 8.2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Nov 2020 19:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697455#M213136</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-11-08T19:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: compute the mid-value of the value of two years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697474#M213148</link>
      <description>Many thanks for your great help.</description>
      <pubDate>Sun, 08 Nov 2020 23:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compute-the-mid-value-of-the-value-of-two-years/m-p/697474#M213148</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2020-11-08T23:27:57Z</dc:date>
    </item>
  </channel>
</rss>

