<?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: How to use proc expand to get the future dates? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-proc-expand-to-get-the-future-dates/m-p/236792#M55268</link>
    <description>Thank you Freelancereinhard and PGStats. Both solutions were very helpful and I used them both. It was good to see different approaches.</description>
    <pubDate>Sat, 28 Nov 2015 01:30:15 GMT</pubDate>
    <dc:creator>krm</dc:creator>
    <dc:date>2015-11-28T01:30:15Z</dc:date>
    <item>
      <title>How to use proc expand to get the future dates?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-proc-expand-to-get-the-future-dates/m-p/236617#M55260</link>
      <description>&lt;P&gt;Hi;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on&amp;nbsp;the sample dataset below and using proc expand to get the missing dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data names;&lt;BR /&gt;input&lt;BR /&gt;name $10. day date7. number ;&lt;BR /&gt;format&lt;BR /&gt;name $10. day date7. ;&lt;BR /&gt;datalines;&lt;BR /&gt;John 12OCT15 3&lt;BR /&gt;John 14OCT15 5&lt;BR /&gt;John 16OCT15 8&lt;BR /&gt;Mike 11OCT15 1&lt;BR /&gt;Mike 13OCT15 7&lt;BR /&gt;Mike 18OCT15 9&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc expand data = names out=names_out from=day to=day method=none;&lt;BR /&gt;by name;&lt;BR /&gt;id day;&lt;BR /&gt;convert number=number / transformout=(setmiss 0.0);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output dataset that I get is just interpolating the missing dates and values for the past dates only. I also want to interpolate the dates to include the maximum date in the dataset. For example in this case since Mike has the most recent date as 18OCT15 I also want John to have 18OCT15 as the max date. The sample data would look like this below (So John would have two extra observations):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;John 12OCT15 3&lt;BR /&gt;John 13OCT15 0&lt;BR /&gt;John 14OCT15 5&lt;BR /&gt;John 15OCT15 0&lt;BR /&gt;John 16OCT15 8&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF9900"&gt;John 17OCT15 0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF9900"&gt;John 18OCT15 0&lt;/FONT&gt;&lt;BR /&gt;Mike 11OCT15 1&lt;BR /&gt;Mike 12OCT15 0&lt;BR /&gt;Mike 13OCT15 7&lt;BR /&gt;Mike 14OCT15 0&lt;BR /&gt;Mike 15OCT15 0&lt;BR /&gt;Mike 16OCT15 0&lt;BR /&gt;Mike 17OCT15 0&lt;BR /&gt;Mike 18OCT15 9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Is it possible to achieve this output using proc expand ? or I should use a different approac?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Nov 2015 16:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-proc-expand-to-get-the-future-dates/m-p/236617#M55260</guid>
      <dc:creator>krm</dc:creator>
      <dc:date>2015-11-26T16:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to use proc expand to get the future dates?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-proc-expand-to-get-the-future-dates/m-p/236651#M55264</link>
      <description>&lt;P&gt;It's probably possible with PROC EXPAND if you first create dummy observations with (overall) minimum and maximum date for each name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it is no problem to get the result without PROC EXPAND (which I don't have licensed anyway). Here is a solution using PROC SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select min(day), max(day)
into :minday, :maxday
from names;
quit;

data alldates;
do day=&amp;amp;minday to &amp;amp;maxday;
  output;
end;
run;

proc sql;
create table want as
select a.name format=$10., a.day format=date7., coalesce(b.number, 0) as number from 
(select * from (select distinct name from names), alldates) a
left join names b
on a.name=b.name &amp;amp; a.day=b.day
order by name, day;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A&amp;nbsp;pure data step solution would also be possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that the above code combines all names with all dates in the range from minimum to maximum. This means that, in addition to the new records you mentioned, John gets a new observation for (Mike's) 11OCT15. If this is not acceptable, we can modify the solution.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Nov 2015 19:00:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-proc-expand-to-get-the-future-dates/m-p/236651#M55264</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-26T19:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to use proc expand to get the future dates?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-proc-expand-to-get-the-future-dates/m-p/236654#M55265</link>
      <description>&lt;P&gt;proc expand complains when you try to do that. A different approach is DIY :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* Get the last date */
proc sql noprint;
select max(day) into :lastDay from names;
quit;

/* Insert missing dates with number=0 */
data names_out;
set names; by name;
previousDay = lag(day);
if not first.name then 
    do newDay = intnx("DAY", previousDay, 1) to intnx("DAY", day, -1);
        newNumber = 0;
        output;
        end;
newDay = day;
newNumber = number;
output;
if last.name then
    do newDay = intnx("DAY", day, 1) to intnx("DAY", &amp;amp;lastDay., 0);
        newNumber = 0;
        output;
        end; 
drop number day previousDay;
rename newNumber=number newDay=day;
format newDay date7.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Nov 2015 19:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-proc-expand-to-get-the-future-dates/m-p/236654#M55265</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-11-26T19:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to use proc expand to get the future dates?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-proc-expand-to-get-the-future-dates/m-p/236792#M55268</link>
      <description>Thank you Freelancereinhard and PGStats. Both solutions were very helpful and I used them both. It was good to see different approaches.</description>
      <pubDate>Sat, 28 Nov 2015 01:30:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-proc-expand-to-get-the-future-dates/m-p/236792#M55268</guid>
      <dc:creator>krm</dc:creator>
      <dc:date>2015-11-28T01:30:15Z</dc:date>
    </item>
  </channel>
</rss>

