<?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 Interpolation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Interpolation/m-p/326223#M72619</link>
    <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would liek to perform interpolation for my data attached.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Identification code = FIPS&lt;/P&gt;
&lt;P&gt;Time period = Year&lt;/P&gt;
&lt;P&gt;7 Variables of interest:&amp;nbsp;assn nccs pvote respn&amp;nbsp;sc_score &amp;nbsp;stdsc_score&lt;/P&gt;
&lt;P&gt;Available data for year 1990, 1997, 2005 and 2009.&lt;/P&gt;
&lt;P&gt;Missing data: 1991 - 1996; 1998 - 2004; 2006 - 2008&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to linearly interpolate the missing data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyone can help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;MSPAK&lt;/P&gt;</description>
    <pubDate>Fri, 20 Jan 2017 10:54:47 GMT</pubDate>
    <dc:creator>mspak</dc:creator>
    <dc:date>2017-01-20T10:54:47Z</dc:date>
    <item>
      <title>Interpolation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Interpolation/m-p/326223#M72619</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would liek to perform interpolation for my data attached.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Identification code = FIPS&lt;/P&gt;
&lt;P&gt;Time period = Year&lt;/P&gt;
&lt;P&gt;7 Variables of interest:&amp;nbsp;assn nccs pvote respn&amp;nbsp;sc_score &amp;nbsp;stdsc_score&lt;/P&gt;
&lt;P&gt;Available data for year 1990, 1997, 2005 and 2009.&lt;/P&gt;
&lt;P&gt;Missing data: 1991 - 1996; 1998 - 2004; 2006 - 2008&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to linearly interpolate the missing data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyone can help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;MSPAK&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 10:54:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Interpolation/m-p/326223#M72619</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2017-01-20T10:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: Interpolation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Interpolation/m-p/326230#M72620</link>
      <description>&lt;P&gt;If you have SAS/ETS then proc expand is the way to go (method=join added in subsequent edit) :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
  set have;
  date=mdy(12,31,year);
  format date date9.;
run;

proc expand data=have2 out=new from=year  method=join;
  by fips;
  id date;
  convert assn nccs pvote respn sc_score std_scscore;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't then a judicious use of lags and arrays will work.&amp;nbsp; The program below assumes that you have data which uniformly has exactly the same missing pattern for all six (I did not see seven) variables. So if ASSN is missing, so are the other 5, and vice versa.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The technique here is to alway have available the curent (in array CURD)&amp;nbsp;and preceding data (array LAGD). The progam also assumes that you are only interpolating and never extrapolating (i.e. you always have the first year and last year not missig).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=cury lagy v coef);
  set have ;
  where assn^=.;
  by fips;

  array d{*}    assn nccs pvote respn sc_score std_scscore ;
  array curd{6} _temporary_;
  array lagd{6} _temporary_;

  cury=year;
  lagy=lag(year);

  do v=1 to dim(d);
    curd{v}=d{v};
    lagd{v}=lag(curd{v});
  end;

  if first.fips then output;
  else do year=lagy+1 to cury;
    coef=(year-lagy)/(cury-lagy);
    do v=1 to dim(d); 
      d{v}=lagd{v} + coef*(curd{v}-lagd{v});
    end;
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 13:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Interpolation/m-p/326230#M72620</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-01-20T13:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: Interpolation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Interpolation/m-p/326231#M72621</link>
      <description>Thank you for the solution. Both of the programs work well. However, the imputed figures as a result of linear interpolation is slightly different.</description>
      <pubDate>Fri, 20 Jan 2017 12:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Interpolation/m-p/326231#M72621</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2017-01-20T12:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Interpolation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Interpolation/m-p/326240#M72626</link>
      <description>&lt;P&gt;I forgot that the default interpolation method for PROC EXPAND is cubic spline.&amp;nbsp; I think using METHOD=JOIN will do linear interpolation. According to the proc expand documentation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A name="etsug_expand000716" target="_blank"&gt;&lt;/A&gt;The JOIN Method&lt;/P&gt;
&lt;P&gt;&lt;A name="etsug.expand.a0000000076" class="indexterm" target="_blank"&gt;&lt;/A&gt;The JOIN method fits a continuous curve to the data by connecting successive straight line segments. For point-in-time data, the JOIN method connects successive nonmissing input values with straight lines. For interval total or average data, interval midpoints are used as the break points, and ordinates are chosen so that the integrals of the piecewise linear curve agree with the input totals.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 13:03:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Interpolation/m-p/326240#M72626</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-01-20T13:03:34Z</dc:date>
    </item>
  </channel>
</rss>

