<?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: Interpolate dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Interpolate-dates/m-p/703541#M215582</link>
    <description>&lt;P&gt;Once upon a time I had a project where I had to implement interpolation of times by almost arbitrary intervals: 5, 10, 15, and 30 minutes, 1, 2, 4, 6, and 12 hours. In ANSI FORTRAN, which had at the time a very limited time sense. I prototyped&amp;nbsp; the project in SAS because the time functions were robust. Then I could check my FORTRAN code results against something.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should specify what rule for the intervals should be.&lt;/P&gt;</description>
    <pubDate>Fri, 04 Dec 2020 02:49:54 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-12-04T02:49:54Z</dc:date>
    <item>
      <title>Interpolate dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Interpolate-dates/m-p/703529#M215578</link>
      <description>&lt;P&gt;Is it possible to interpolate dates using start and end dates ?&lt;/P&gt;&lt;P&gt;Also is it possible to interpolate missing dates based on some other variable in the dataset?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Longitude&lt;/TD&gt;&lt;TD&gt;Dates&lt;/TD&gt;&lt;TD&gt;Quantity&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;24.5&lt;/TD&gt;&lt;TD&gt;24May2018&lt;/TD&gt;&lt;TD&gt;340000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;25.5&lt;/TD&gt;&lt;TD&gt;missing&lt;/TD&gt;&lt;TD&gt;340000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;26&lt;/TD&gt;&lt;TD&gt;missing&lt;/TD&gt;&lt;TD&gt;320000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;27&lt;/TD&gt;&lt;TD&gt;missing&lt;/TD&gt;&lt;TD&gt;300000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;28&lt;/TD&gt;&lt;TD&gt;missing&lt;/TD&gt;&lt;TD&gt;280000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;28.5&lt;/TD&gt;&lt;TD&gt;missing&lt;/TD&gt;&lt;TD&gt;240000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29&lt;/TD&gt;&lt;TD&gt;missing&lt;/TD&gt;&lt;TD&gt;210000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;missing&lt;/TD&gt;&lt;TD&gt;180000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;30.3&lt;/TD&gt;&lt;TD&gt;31Dec2018&lt;/TD&gt;&lt;TD&gt;175000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 00:42:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Interpolate-dates/m-p/703529#M215578</guid>
      <dc:creator>hastm</dc:creator>
      <dc:date>2020-12-04T00:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: Interpolate dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Interpolate-dates/m-p/703533#M215579</link>
      <description>&lt;P&gt;Because SAS can stores date values as numbers (number of days after 01jan1960, or negative values for prior to 01jan1960), the answer is yes, you can interpolate dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I presume you want to take, for each longitude, it's relative position between longitudes with know dates, and apply that same relative progress to the time span between the known dates, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  invalue indate  'missing'=. other=[date9.];
run;
data have;
  input Longitude	Date :indate9.	Quantity;
  format date date9. ;
datalines;
24.5	24May2018	340000
25.5	missing	340000
26	missing	320000
27	missing	300000
28	missing	280000
28.5	missing	240000
29	missing	210000
30	missing	180000
30.3	31Dec2018	175000
run;


data want (drop=_:);
  do _n=1 by 1 until (date^=.);
	set have;
  end;
  _startdate=lag(date);
  _ndays=dif(date);            /* dif(date) means date-lag(date) */

  _startlong=lag(longitude);
  _difflong=dif(longitude);

  do _i=1 to _n ;
    set have;
	if _difflong^=. and date=. then date =   _startdate + _ndays*(longitude-_startlong)/_difflong;
	output;
  end;
run;&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But please be aware that the interpolated date values above need not be integers, even though displaying them with the date9. format will look the same as if they were integers.&amp;nbsp; &amp;nbsp;For instance the underlying date value for 24May2018 is 21328.&amp;nbsp; But if you had a value of, say 21328.99, and you applied the date9. format to its display, it would still appear as 24MAY2018.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could make all the interpolated values into integers, if you wish.&amp;nbsp; But if you do so, I'd suggest the FLOOR function (instead of round, or ceiling), just to be consistent with the date9. format.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 01:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Interpolate-dates/m-p/703533#M215579</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-12-04T01:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: Interpolate dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Interpolate-dates/m-p/703541#M215582</link>
      <description>&lt;P&gt;Once upon a time I had a project where I had to implement interpolation of times by almost arbitrary intervals: 5, 10, 15, and 30 minutes, 1, 2, 4, 6, and 12 hours. In ANSI FORTRAN, which had at the time a very limited time sense. I prototyped&amp;nbsp; the project in SAS because the time functions were robust. Then I could check my FORTRAN code results against something.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should specify what rule for the intervals should be.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 02:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Interpolate-dates/m-p/703541#M215582</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-04T02:49:54Z</dc:date>
    </item>
  </channel>
</rss>

