<?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 Replacing the missing value with earlier date or later date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414386#M101528</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I need your kind help to replace the missing value of a column with the previous date's value where as in case of missing first observation, the value will be replaced by next available value.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
format date date9.;
input id $ LHIN 2. date date9. pulse 3. ;
datalines;
101 1 01JAN2017 90
101 1 03JAN2017 80
101 1 05JAN2017   
102 2 01JAN2017 90
102 2 03JAN2017 
102 3 05JAN2017 70
103 2 03JAN2017 
103 3 05JAN2017 70
103 3 06JAN2017 70
104 2 03JAN2017 
104 3 05JAN2017 
104 3 06JAN2017 70
;
run;



data want;
format date date9.;
input id $ LHIN 2. date date9. pulse 3. ;
datalines;
101 1 01JAN2017 90
101 1 03JAN2017 80
101 1 05JAN2017 80
102 2 01JAN2017 90
102 2 03JAN2017 90
102 3 05JAN2017 70
103 2 03JAN2017 80
103 3 05JAN2017 80
103 3 06JAN2017 70
104 2 03JAN2017 70
104 3 05JAN2017 70
104 3 06JAN2017 70
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you in advance for your kind reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Nov 2017 14:21:31 GMT</pubDate>
    <dc:creator>DeepakSwain</dc:creator>
    <dc:date>2017-11-17T14:21:31Z</dc:date>
    <item>
      <title>Replacing the missing value with earlier date or later date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414386#M101528</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I need your kind help to replace the missing value of a column with the previous date's value where as in case of missing first observation, the value will be replaced by next available value.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
format date date9.;
input id $ LHIN 2. date date9. pulse 3. ;
datalines;
101 1 01JAN2017 90
101 1 03JAN2017 80
101 1 05JAN2017   
102 2 01JAN2017 90
102 2 03JAN2017 
102 3 05JAN2017 70
103 2 03JAN2017 
103 3 05JAN2017 70
103 3 06JAN2017 70
104 2 03JAN2017 
104 3 05JAN2017 
104 3 06JAN2017 70
;
run;



data want;
format date date9.;
input id $ LHIN 2. date date9. pulse 3. ;
datalines;
101 1 01JAN2017 90
101 1 03JAN2017 80
101 1 05JAN2017 80
102 2 01JAN2017 90
102 2 03JAN2017 90
102 3 05JAN2017 70
103 2 03JAN2017 80
103 3 05JAN2017 80
103 3 06JAN2017 70
104 2 03JAN2017 70
104 3 05JAN2017 70
104 3 06JAN2017 70
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you in advance for your kind reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 14:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414386#M101528</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2017-11-17T14:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing the missing value with earlier date or later date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414395#M101530</link>
      <description>&lt;P&gt;There is quite a few posts on this subject.&amp;nbsp; There are various methods, some guys like the update or hashtable.&amp;nbsp; Me I would just go with retained value:&lt;/P&gt;
&lt;PRE&gt;data want (drop=p);
  set have (rename=(pulse=p));
  retain pulse;
  if p ne . then pulse=p;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Nov 2017 14:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414395#M101530</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-17T14:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing the missing value with earlier date or later date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414418#M101539</link>
      <description>&lt;P&gt;Hi RW9,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code seems to be very simple and great. Is it possible to do little modification so that the value carried forward wiil be depenedednt on ID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 15:27:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414418#M101539</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2017-11-17T15:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing the missing value with earlier date or later date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414433#M101543</link>
      <description>&lt;P&gt;Yep:&lt;/P&gt;
&lt;PRE&gt;data want (drop=p);
  set have (rename=(pulse=p));&lt;BR /&gt;  by id;
  retain pulse;&lt;BR /&gt;  if first.id then pulse=p;
  if p ne . then pulse=p;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Nov 2017 15:48:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414433#M101543</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-17T15:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing the missing value with earlier date or later date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414446#M101546</link>
      <description>&lt;P&gt;Hi RW9,&lt;/P&gt;&lt;P&gt;Unfortunately for ID 101 ,&lt;/P&gt;&lt;P&gt;I am getting:&amp;nbsp;&lt;/P&gt;&lt;P&gt;date id LHIN pulse&lt;BR /&gt;01-Jan-17 101 1 90&lt;BR /&gt;03-Jan-17 101 1 80&lt;BR /&gt;05-Jan-17 101 1 70&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected:&lt;/P&gt;&lt;P&gt;101 1 01JAN2017 90&lt;BR /&gt;101 1 03JAN2017 80&lt;BR /&gt;101 1 05JAN2017 80&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 16:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414446#M101546</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2017-11-17T16:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing the missing value with earlier date or later date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414454#M101548</link>
      <description>&lt;P&gt;Please provide test data&amp;nbsp;&lt;STRONG&gt;exactly as it is.&amp;nbsp;&lt;/STRONG&gt; I have run the code:&lt;/P&gt;
&lt;PRE&gt;data have ;
format date date9.;
input id $ LHIN 2. date date9. pulse 3. ;
datalines;
101 1 01JAN2017 90
101 1 03JAN2017 80
101 1 05JAN2017   
102 2 01JAN2017 90
102 2 03JAN2017 
102 3 05JAN2017 70
103 2 03JAN2017 
103 3 05JAN2017 70
103 3 06JAN2017 70
104 2 03JAN2017 
104 3 05JAN2017 
104 3 06JAN2017 70
;
run;

data want (drop=p);
  set have (rename=(pulse=p));
  by id;
  retain pulse;
  if first.id then pulse=p;
  if p ne . then pulse=p;
run;&lt;/PRE&gt;
&lt;P&gt;And it shows the correct value of 80, I suspect your data is not sorted correctly or something.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 16:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414454#M101548</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-17T16:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing the missing value with earlier date or later date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414490#M101555</link>
      <description>&lt;P&gt;Hi RW9,&lt;/P&gt;&lt;P&gt;It is not working for ID 103 and 104:&lt;/P&gt;&lt;P&gt;03-Jan-17 103 2 .&lt;BR /&gt;05-Jan-17 103 3 70&lt;BR /&gt;06-Jan-17 103 3 70&lt;BR /&gt;03-Jan-17 104 2 .&lt;BR /&gt;05-Jan-17 104 3 .&lt;BR /&gt;06-Jan-17 104 3 70&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still the missing values are there. The missing values are expected to be filled with latest value, if older value is not available.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 18:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414490#M101555</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2017-11-17T18:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing the missing value with earlier date or later date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414505#M101557</link>
      <description>Hi RW9,&lt;BR /&gt;&lt;BR /&gt;Retain value provides the previous value. If very first value is missing and we want to fill it with the next available. How to proceed.&lt;BR /&gt;Regards,&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Nov 2017 19:10:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414505#M101557</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2017-11-17T19:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing the missing value with earlier date or later date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414591#M101591</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/re-Missing-Entries/m-p/414194#M101476" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/re-Missing-Entries/m-p/414194#M101476&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Nov 2017 10:29:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414591#M101591</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-18T10:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing the missing value with earlier date or later date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414784#M101660</link>
      <description>&lt;P&gt;In which case you need to do a couple of steps:&lt;/P&gt;
&lt;PRE&gt;proc sort data=have out=temp;
  by id date;
  where val ne .;
run;
data temp (rename=(val=base));
  set temp;
  by id;
  if first.id;
run;

data want (drop=base);
  merge have want;
  by id;
  if val=. then val=base;
run;&lt;/PRE&gt;
&lt;P&gt;This gets the first non-missing value, if there is one, and merges that back to your original data and replaces that value with the missing in original data.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2017 09:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-the-missing-value-with-earlier-date-or-later-date/m-p/414784#M101660</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-20T09:19:31Z</dc:date>
    </item>
  </channel>
</rss>

