<?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 extarct first and last timestamp in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357861#M84054</link>
    <description>&lt;P&gt;Please post an example of your expected output data. 04DEC12:14:06:00 IS the maximum timestamp, for all ICU's and for ICU 1, so I don't see why you would not want that to be the result.&lt;/P&gt;</description>
    <pubDate>Thu, 11 May 2017 12:50:52 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-05-11T12:50:52Z</dc:date>
    <item>
      <title>How to extarct first and last timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357847#M84051</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having trouble extracting the first and last&amp;nbsp;timestamp for the single encounter who was admitted in different ICUs in the same admission from the data below. I am sorting data on id and&amp;nbsp;ICU and using proc summary to extract the first and last time stamp but sorting data on id and icu is not what i want. i am getting&amp;nbsp; first timestamp for ICU 1 29NOV12:14:06:00&amp;nbsp; and last tmestamp i am getting&amp;nbsp;is 04DEC12:14:06:00 which i donot want.&amp;nbsp;I want first and last timesamp for individual ICU no matter if it is in the same ICU.&amp;nbsp;Any input would be appreciated.&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;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; icustay;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;infile&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; datalines &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;missover&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; id ts : &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;datetime.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ICU ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ts &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;datetime.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;5307 29NOV12:14:06:00 1&lt;/P&gt;&lt;P&gt;5307 29NOV12:15:45:00 1&lt;/P&gt;&lt;P&gt;5307 30NOV12:17:00:00 1&lt;/P&gt;&lt;P&gt;5307 30NOV12:20:06:00 1&lt;/P&gt;&lt;P&gt;5307 01DEC12:14:06:00 2&lt;/P&gt;&lt;P&gt;5307 01DEC12:20:16:00 2&lt;/P&gt;&lt;P&gt;5307 02DEC12:21:06:00 2&lt;/P&gt;&lt;P&gt;5307 03DEC12:14:06:00 1&lt;/P&gt;&lt;P&gt;5307 03DEC12:20:06:00 1&lt;/P&gt;&lt;P&gt;5307 04DEC12:14:06:00 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;print&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=work.icustay;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 12:36:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357847#M84051</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2017-05-11T12:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to extarct first and last timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357861#M84054</link>
      <description>&lt;P&gt;Please post an example of your expected output data. 04DEC12:14:06:00 IS the maximum timestamp, for all ICU's and for ICU 1, so I don't see why you would not want that to be the result.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 12:50:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357861#M84054</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-11T12:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to extarct first and last timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357862#M84055</link>
      <description>&lt;P&gt;There are quite a few topics on this here. &amp;nbsp;Its simple process:&lt;/P&gt;
&lt;PRE&gt;data want;
  set icustay;
  by id icu notsorted;
  if first.icu or last.icu then output;
run;&lt;/PRE&gt;
&lt;P&gt;This goes through your data as it is, outputting first and last of each icu category.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 12:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357862#M84055</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-11T12:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to extarct first and last timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357865#M84057</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi KurtBremser, below is the example of the output i want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for yoyur reply&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ts&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;unit&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;first&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last&lt;/P&gt;&lt;P&gt;5307&amp;nbsp; 29NOV12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 29NOV12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30NOV12:20:06:00&amp;nbsp;&lt;/P&gt;&lt;P&gt;5307&amp;nbsp; 29NOV12:15:45:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 29NOV12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30NOV12:20:06:00&amp;nbsp;&lt;/P&gt;&lt;P&gt;5307 &amp;nbsp;30NOV12:17:00:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;29NOV12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30NOV12:20:06:00&amp;nbsp;&lt;/P&gt;&lt;P&gt;5307&amp;nbsp;&amp;nbsp;30NOV12:20:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 29NOV12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30NOV12:20:06:00&amp;nbsp;&lt;/P&gt;&lt;P&gt;5307&amp;nbsp; 01DEC12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;01DEC12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;02DEC12:21:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5307 &amp;nbsp;01DEC12:20:16:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;01DEC12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 02DEC12:21:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5307&amp;nbsp; 02DEC12:21:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01DEC12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 02DEC12:21:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5307&amp;nbsp; 03DEC12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;03DEC12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;04DEC12:14:06:00&lt;/P&gt;&lt;P&gt;5307&amp;nbsp; 03DEC12:20:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 03DEC12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 04DEC12:14:06:00&lt;/P&gt;&lt;P&gt;5307&amp;nbsp; 04DEC12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 03DEC12:14:06:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 04DEC12:14:06:00&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 12:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357865#M84057</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2017-05-11T12:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to extarct first and last timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357874#M84061</link>
      <description>&lt;P&gt;Thank you very much RW9. i highly appreciate your help.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 13:16:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357874#M84061</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2017-05-11T13:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to extarct first and last timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357875#M84062</link>
      <description>&lt;P&gt;This is how you get the min/max per individual ICU stay:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep=id icu mints maxts);
set icustay;
by id icu notsorted;
retain mints maxts;
format mints maxts datetime.;
if first.icu then mints = ts;
if last.icu
then do;
  maxts = ts;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;assuming that the dataset is correctly sorted by id and ts.&lt;/P&gt;
&lt;P&gt;If you want to merge back to get the expanded output you posted, you would need to create a "stay identifier" first along the by values I used.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 13:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357875#M84062</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-11T13:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to extarct first and last timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357879#M84063</link>
      <description>&lt;P&gt;Thank you very much for your help. can you please explain where i need to create the identifier you are saying to merge with the output i posted&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 13:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357879#M84063</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2017-05-11T13:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to extarct first and last timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357881#M84065</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/120524"&gt;@AMFR&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much for your help. can you please explain where i need to create the identifier you are saying to merge with the output i posted&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This would look like that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=icustay;
by id ts;
run;
/* just to make sure for larger datasets */

data intermediate;
set icustay;
by id icu notsorted;
retain staycount 0;
if first.icu then staycount + 1;
run;

data minmax (keep=staycount mints maxts);
set intermediate;
by staycount;
retain mints maxts;
format mints maxts datetime.;
if first.staycount then mints = ts;
if last.staycount
then do;
  maxts = ts;
  output;
end;
run;

data result;
merge intermediate minmax;
by staycount;
drop staycount;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 May 2017 13:29:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357881#M84065</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-11T13:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to extarct first and last timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357883#M84066</link>
      <description>&lt;P&gt;This is eaxctly what I was looking for. You are amzing. Thank you very much&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 13:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extarct-first-and-last-timestamp/m-p/357883#M84066</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2017-05-11T13:36:33Z</dc:date>
    </item>
  </channel>
</rss>

