<?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 do I seperate a variable by datetime to capture values at a specific time only in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809312#M319135</link>
    <description>&lt;P&gt;In that case you could still use PROC TRANSPOSE and for the output run a datastep with a where clause removing null instance of&amp;nbsp;&lt;SPAN&gt;FiO2 and Spo2&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Apr 2022 13:55:39 GMT</pubDate>
    <dc:creator>HarrySnart</dc:creator>
    <dc:date>2022-04-22T13:55:39Z</dc:date>
    <item>
      <title>How do I seperate a variable by datetime to capture values at a specific time only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809248#M319096</link>
      <description>&lt;P&gt;I want to pick values of Spo2 and Fio2 that occur at the same time. I am trying to transform the have to want dataset.&amp;nbsp; I have a huge dataset but i have created a subset here for clarity. Please help i am a new programmer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TheBlackBishop1_0-1650621120896.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70733i8FD70EDD33949A02/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TheBlackBishop1_0-1650621120896.png" alt="TheBlackBishop1_0-1650621120896.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input datetime $disp_name Value;&lt;BR /&gt;datalines;&lt;BR /&gt;1/1/2012 1:29:00 PM SpO2 90&lt;BR /&gt;1/1/2012 1:29:00 PM Fio2 100&lt;BR /&gt;1/1/2012 2:21:00 PM SpO2 89&lt;BR /&gt;1/1/2012 2:21:00 PM Fio2 100&lt;BR /&gt;1/1/2012 4:09:00 PM SpO2 87&lt;BR /&gt;1/1/2012 4:09:00 PM Fio2 99&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;input datetime SpO2 Fio2;&lt;BR /&gt;datalines;&lt;BR /&gt;1/1/2012 1:29:00 PM 90 100&lt;BR /&gt;1/1/2012 2:21:00 PM 89 100&lt;BR /&gt;1/1/2012 4:09:00 PM 87 99&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 09:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809248#M319096</guid>
      <dc:creator>TheBlackBishop1</dc:creator>
      <dc:date>2022-04-22T09:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I seperate a variable by datetime to capture values at a specific time only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809255#M319100</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222002"&gt;@TheBlackBishop1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input datetime $disp_name Value;&lt;BR /&gt;datalines;&lt;BR /&gt;1/1/2012 1:29:00 PM SpO2 90&lt;BR /&gt;1/1/2012 1:29:00 PM Fio2 100&lt;BR /&gt;1/1/2012 2:21:00 PM SpO2 89&lt;BR /&gt;1/1/2012 2:21:00 PM Fio2 100&lt;BR /&gt;1/1/2012 4:09:00 PM SpO2 87&lt;BR /&gt;1/1/2012 4:09:00 PM Fio2 99&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222002"&gt;@TheBlackBishop1&lt;/a&gt;&amp;nbsp;I realize you are new here, but it would help everyone if you would please test your code before posting to make sure it works. This code doesn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my solution, which is untested, because I don't have your data (or working code from you)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want;
    by datetime;
    var value;
    id disp_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Apr 2022 10:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809255#M319100</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-22T10:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I seperate a variable by datetime to capture values at a specific time only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809258#M319101</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222002"&gt;@TheBlackBishop1&lt;/a&gt;&amp;nbsp; your input datalines didn't work but this can be achieved using PROC TRANSPOSE.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=have;title 'Initial Data';run;

proc sort data=WORK.HAVE out=WORK.SORTTempTableSorted;
	by datetime;
run;

proc transpose data=WORK.SORTTempTableSorted out=want ;
	var value;
	id disp_name;


	by datetime;
run;

proc print data=want;
	title "Output of Transpose Procedure"; var datetime sp02 fio2;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HarrySnart_0-1650624538994.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70734i8CD6137C052FE7DB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HarrySnart_0-1650624538994.png" alt="HarrySnart_0-1650624538994.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 10:49:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809258#M319101</guid>
      <dc:creator>HarrySnart</dc:creator>
      <dc:date>2022-04-22T10:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I seperate a variable by datetime to capture values at a specific time only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809264#M319105</link>
      <description>&lt;P&gt;Do Fio2 and Spo2 both always exist for one time?&lt;/P&gt;
&lt;P&gt;If not: what is the expected output in such case?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 11:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809264#M319105</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-04-22T11:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I seperate a variable by datetime to capture values at a specific time only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809301#M319134</link>
      <description>FiO2 and Spo2 don’t always exist for one time. I am only interested in when&lt;BR /&gt;they both exist for one time.&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Apr 2022 13:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809301#M319134</guid>
      <dc:creator>TheBlackBishop1</dc:creator>
      <dc:date>2022-04-22T13:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I seperate a variable by datetime to capture values at a specific time only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809312#M319135</link>
      <description>&lt;P&gt;In that case you could still use PROC TRANSPOSE and for the output run a datastep with a where clause removing null instance of&amp;nbsp;&lt;SPAN&gt;FiO2 and Spo2&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 13:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809312#M319135</guid>
      <dc:creator>HarrySnart</dc:creator>
      <dc:date>2022-04-22T13:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I seperate a variable by datetime to capture values at a specific time only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809320#M319139</link>
      <description>&lt;P&gt;Thank you for this response. But i have one challenge. I need to maintain them by both the mrn and enc (encounter id). How would the proc transpose work in this case? (sorry about my input code. I have corrected it and it works now)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input mrn enc datetime$ 9-26 disp_name$ Value;&lt;BR /&gt;datalines;&lt;BR /&gt;123 341 1/1/2012 1:29:00PM SpO2 90&lt;BR /&gt;123 341 1/1/2012 1:29:00PM Fio2 100&lt;BR /&gt;123 341 1/1/2012 2:21:00PM SpO2 89&lt;BR /&gt;123 341 1/1/2012 2:21:00PM Fio2 100&lt;BR /&gt;245 456 1/1/2012 4:09:00PM SpO2 87&lt;BR /&gt;245 456 1/1/2012 4:09:00PM Fio2 99&lt;BR /&gt;245 222 1/3/2012 3:09:00PM SpO2 88&lt;BR /&gt;245 222 1/3/2012 3:09:00PM Fio2 100&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 14:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809320#M319139</guid>
      <dc:creator>TheBlackBishop1</dc:creator>
      <dc:date>2022-04-22T14:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I seperate a variable by datetime to capture values at a specific time only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809321#M319140</link>
      <description>&lt;P&gt;Hi, I am sorry about my code. This works now. I want to keep them by MRN(medical record number) and ENC (encounter ID). How would the proc transpose work? Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input mrn enc datetime$ 9-26 disp_name$ Value;&lt;BR /&gt;datalines;&lt;BR /&gt;123 341 1/1/2012 1:29:00PM SpO2 90&lt;BR /&gt;123 341 1/1/2012 1:29:00PM Fio2 100&lt;BR /&gt;123 341 1/1/2012 2:21:00PM SpO2 89&lt;BR /&gt;123 341 1/1/2012 2:21:00PM Fio2 100&lt;BR /&gt;245 456 1/1/2012 4:09:00PM SpO2 87&lt;BR /&gt;245 456 1/1/2012 4:09:00PM Fio2 99&lt;BR /&gt;245 222 1/3/2012 3:09:00PM SpO2 88&lt;BR /&gt;245 222 1/3/2012 3:09:00PM Fio2 100&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 14:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809321#M319140</guid>
      <dc:creator>TheBlackBishop1</dc:creator>
      <dc:date>2022-04-22T14:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I seperate a variable by datetime to capture values at a specific time only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809324#M319142</link>
      <description>&lt;P&gt;Just add them to the BY statement.&lt;/P&gt;
&lt;P&gt;Not sure why you posted data that is not actually sorted by the variables (at least by the variables in the order they appear in your dataset).&amp;nbsp; You might need to sort the data. Or change the order of the variables in BY statement to match the sort order if it is sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But your sample data is grouped already even if it is not actually sorted so you could add the NOTSORTED keyword to the BY statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input mrn enc datetime$ 9-26 disp_name$ Value;
datalines;
123 341 1/1/2012 1:29:00PM SpO2 90
123 341 1/1/2012 1:29:00PM Fio2 100
123 341 1/1/2012 2:21:00PM SpO2 89
123 341 1/1/2012 2:21:00PM Fio2 100
245 456 1/1/2012 4:09:00PM SpO2 87
245 456 1/1/2012 4:09:00PM Fio2 99
245 222 1/3/2012 3:09:00PM SpO2 88
245 222 1/3/2012 3:09:00PM Fio2 100
;

proc transpose data=have out=want(drop=_name_);
  by mrn enc datetime NOTSORTED ;
  var value;
  id disp_name;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    mrn    enc         datetime         SpO2    Fio2

 1     123    341    1/1/2012 1:29:00PM     90      100
 2     123    341    1/1/2012 2:21:00PM     89      100
 3     245    456    1/1/2012 4:09:00PM     87       99
 4     245    222    1/3/2012 3:09:00PM     88      100
&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Apr 2022 14:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809324#M319142</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-22T14:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I seperate a variable by datetime to capture values at a specific time only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809330#M319146</link>
      <description>&lt;P&gt;Thank you for your help. Its clear now.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 15:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809330#M319146</guid>
      <dc:creator>TheBlackBishop1</dc:creator>
      <dc:date>2022-04-22T15:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I seperate a variable by datetime to capture values at a specific time only</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809362#M319171</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/335473"&gt;@HarrySnart&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;In that case you could still use PROC TRANSPOSE and for the output run a datastep with a where clause removing null instance of&amp;nbsp;&lt;SPAN&gt;FiO2 and Spo2&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Or a data set option on the output data set of proc transpose with something like where=( not missing(FiO2) and not missing(Spo2)) along with the drop _name_.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 17:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-seperate-a-variable-by-datetime-to-capture-values-at-a/m-p/809362#M319171</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-04-22T17:08:21Z</dc:date>
    </item>
  </channel>
</rss>

