<?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 retain values in a SAS dataset with datetime? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829084#M327539</link>
    <description>&lt;P&gt;I did not know that this was a feature of PROC TIMESERIES. Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 17 Aug 2022 17:15:07 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-08-17T17:15:07Z</dc:date>
    <item>
      <title>How to retain values in a SAS dataset with datetime?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829041#M327518</link>
      <description>&lt;P&gt;Hi experts,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help retaining values in a SAS dataset and completing the column datetime (to the level of seconds) when not existing.&lt;/P&gt;&lt;P&gt;My dataset looks like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data HAVE;  
input type$ DATE:datetime18. value;
format date datetime18.;
cards;

A 19JUN01:21:06:55 534
A 19JUN01:21:06:58 590
A 19JUN01:21:07:02 600
A 19JUN01:21:07:04 602
B 18JUN01:22:06:58 105
B 18JUN01:22:07:03 110
;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need to fill the missing datetime and repeat the value when needed.&lt;/P&gt;&lt;P&gt;My result dataset should be:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data WANT;  
input type$ DATE:datetime18. value;
format date datetime18.;
    cards;

A 19JUN01:21:06:55 534
A 19JUN01:21:06:56 534
A 19JUN01:21:06:57 534
A 19JUN01:21:06:58 590
A 19JUN01:21:06:59 590
A 19JUN01:21:07:00 590
A 19JUN01:21:07:01 590
A 19JUN01:21:07:02 600
A 19JUN01:21:07:03 600
A 19JUN01:21:07:04 602
B 18JUN01:22:06:58 105
B 18JUN01:22:06:59 105
B 18JUN01:22:07:00 105
B 18JUN01:22:07:01 105
B 18JUN01:22:07:02 105
B 18JUN01:22:07:03 110
    ;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks for your suggestions. Regards&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 14:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829041#M327518</guid>
      <dc:creator>MM88</dc:creator>
      <dc:date>2022-08-17T14:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain values in a SAS dataset with datetime?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829080#M327535</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;  
input type$ DATE:datetime18. value;
format date datetime18.;
cards;
A 19JUN01:21:06:55 534
A 19JUN01:21:06:58 590
A 19JUN01:21:07:02 600
A 19JUN01:21:07:04 602
B 18JUN01:22:06:58 105
B 18JUN01:22:07:03 110
;
run; 

proc timeseries data=have out=want;
   by type;
   id date interval = second
           setmiss  = prev;
   var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;type  DATE              value
A     19JUN01:21:06:55  534
A     19JUN01:21:06:56  534
A     19JUN01:21:06:57  534
A     19JUN01:21:06:58  590
A     19JUN01:21:06:59  590
A     19JUN01:21:07:00  590
A     19JUN01:21:07:01  590
A     19JUN01:21:07:02  600
A     19JUN01:21:07:03  600
A     19JUN01:21:07:04  602
B     18JUN01:22:06:58  105
B     18JUN01:22:06:59  105
B     18JUN01:22:07:00  105
B     18JUN01:22:07:01  105
B     18JUN01:22:07:02  105
B     18JUN01:22:07:03  110&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Aug 2022 17:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829080#M327535</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-17T17:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain values in a SAS dataset with datetime?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829084#M327539</link>
      <description>&lt;P&gt;I did not know that this was a feature of PROC TIMESERIES. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 17:15:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829084#M327539</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-17T17:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain values in a SAS dataset with datetime?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829097#M327548</link>
      <description>&lt;P&gt;Yeah, Proc Timeseries is quite cool for tasks like this &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 18:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829097#M327548</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-17T18:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain values in a SAS dataset with datetime?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829101#M327550</link>
      <description>&lt;P&gt;You don't have ETS licensed then just use a data step.&amp;nbsp; The tricky part is find the value of the next "date" (actually in this case the next datetime).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;  
  input type $ DATE :datetime. value;
  format date datetime19.;
cards;
A 19JUN01:21:06:55 534
A 19JUN01:21:06:58 590
A 19JUN01:21:07:02 600
A 19JUN01:21:07:04 602
B 18JUN01:22:06:58 105
B 18JUN01:22:07:03 110
;

data want;
  set have;
  by type date;
  set have(firstobs=2 keep=date rename=(date=next_date)) have(obs=1 drop=_all_);
  if last.type then next_date=.;
  else next_date=next_date-1;
  do date=date to coalesce(next_date,date);
    output;
  end;
  drop next_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1660762472282.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74498i579235776A88EF08/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1660762472282.png" alt="Tom_0-1660762472282.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 18:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829101#M327550</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-17T18:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain values in a SAS dataset with datetime?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829151#M327573</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;,&lt;BR /&gt;Thanks for your solution. Unfortunately I don´t have SAS/ETS.&lt;BR /&gt;Regards</description>
      <pubDate>Thu, 18 Aug 2022 06:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829151#M327573</guid>
      <dc:creator>MM88</dc:creator>
      <dc:date>2022-08-18T06:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain values in a SAS dataset with datetime?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829183#M327586</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;  
  input type $ DATE :datetime. value;
  format date datetime19.;
cards;
A 19JUN01:21:06:55 534
A 19JUN01:21:06:58 590
A 19JUN01:21:07:02 600
A 19JUN01:21:07:04 602
B 18JUN01:22:06:58 105
B 18JUN01:22:07:03 110
;

data want;
  merge have have(keep=type date rename=(type=_type date=_date) firstobs=2);
  output;
  if type=_type then do;
    do date=date+1 to _date-1;
  output;
 end;
  end;
drop _type _date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2022 12:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-values-in-a-SAS-dataset-with-datetime/m-p/829183#M327586</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-08-18T12:27:47Z</dc:date>
    </item>
  </channel>
</rss>

