<?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: SAS/SQL: Find the median of three times, not min/max in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Find-the-median-of-three-times-not-min-max/m-p/582912#M165876</link>
    <description>If you use a data step you can use CALL SORT()&lt;BR /&gt;&lt;BR /&gt;If you're using SQL, you'll have to use CASE statements to explicitly create the order. SQL works with columns at a time, not rows. &lt;BR /&gt;&lt;BR /&gt;Did my previous solution not work? If so, how did it not work?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This will sort your times. &lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;call sort (time1, time2, time3);&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;</description>
    <pubDate>Wed, 21 Aug 2019 17:39:12 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-08-21T17:39:12Z</dc:date>
    <item>
      <title>SAS/SQL: Find the median of three times, not min/max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Find-the-median-of-three-times-not-min-max/m-p/582910#M165874</link>
      <description>&lt;P&gt;Follow-Up/Related to my previous question:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/SAS-SQL-3-times-check-if-there-s-an-interval-greater-than-2/m-p/582596/highlight/false#M165725" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/SAS-SQL-3-times-check-if-there-s-an-interval-greater-than-2/m-p/582596/highlight/false#M165725&lt;/A&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I have 3 times, how can I sort it so that it goes from least to greatest or greatest to least?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;╔═════════╦══════════╦══════════╦═══════════╦═══════════╗
║ Subject ║ TimeONE  ║ TimeTWO  ║ TimeTHREE ║ TimePoint ║
╠═════════╬══════════╬══════════╬═══════════╬═══════════╣
║       1 ║ 11:13:10 ║ 11:17:10 ║ 11:15:10  ║ s1        ║
║       1 ║          ║ 12:00:01 ║ 9:05:00   ║ s2        ║
╚═════════╩══════════╩══════════╩═══════════╩═══════════╝&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;╔═════════╦══════════╦══════════╦═══════════╦═══════════╗
║ Subject ║ TimeONE  ║ TimeTWO  ║ TimeTHREE ║ TimePoint ║
╠═════════╬══════════╬══════════╬═══════════╬═══════════╣
║       1 ║ 11:13:10 ║ 11:15:10 ║ 11:17:10  ║ s1        ║
║       1 ║          ║ 9:05:00  ║ 12:00:01  ║ s2        ║
╚═════════╩══════════╩══════════╩═══════════╩═══════════╝&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;╔═════════╦══════════╦══════════╦═══════════╦═══════════╗
║ Subject ║ TimeONE  ║ TimeTWO  ║ TimeTHREE ║ TimePoint ║
╠═════════╬══════════╬══════════╬═══════════╬═══════════╣
║       1 ║ 11:13:10 ║ 11:15:10 ║ 11:17:10  ║ s1        ║
║       1 ║ 9:05:00  ║ 12:00:01 ║           ║ s2        ║
╚═════════╩══════════╩══════════╩═══════════╩═══════════╝&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Current code based on this data table:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;╔═════════╦══════════╦════════════╗
║ Subject ║  Time1   ║  TimePoint ║
╠═════════╬══════════╬════════════╣
║       1 ║ 11:13:10 ║  s1        ║
║       1 ║ 11:15:10 ║  s1        ║
║       1 ║ 11:17:30 ║  s1        ║
║       1 ║ 11:45    ║  s2        ║
║       1 ║          ║  s2        ║
║       1 ║ 11:50    ║  s2        ║
╚═════════╩══════════╩════════════╝&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
CREATE TABLE t1 AS
SELECT DISTINCT *
FROM have
GROUP BY Subject, timepoint
HAVING timepoint IS NOT NULL
ORDER BY  TimeOne, TimeTWO, TimeThree
;

CREATE TABLE t4 AS
SELECT t1.Subject, t1.timepoint, 
t1.EG1TIM AS T1, t2.EG1TIM AS T2, t3.EG1TIM AS T3, 0 AS T3_MINUS_T2, 0 AS T2_MINUS_T1, 0 AS T3_MINUS_T1
FROM t1, t1 t2, t1 t3
WHERE /*make sure same subject and same timepoint */
order by t1.eg1tim 
;&lt;BR /&gt;&lt;BR /&gt;/*This essentially becomes the input/output table shown at the very top of this post, but not sorted */

quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm just stuck on sorting the 3 times. I need to determine, given it's sorted, if there's an interval that's &amp;gt; 2min (120seconds)&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;EDIT after accepting solution:&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I used sortc(Time1, Time2, Time3) and then just manually find the difference of each interval, taking into account if a Time is null in a data step.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 19:45:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Find-the-median-of-three-times-not-min-max/m-p/582910#M165874</guid>
      <dc:creator>jerrylshen</dc:creator>
      <dc:date>2019-08-21T19:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL: Find the median of three times, not min/max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Find-the-median-of-three-times-not-min-max/m-p/582912#M165876</link>
      <description>If you use a data step you can use CALL SORT()&lt;BR /&gt;&lt;BR /&gt;If you're using SQL, you'll have to use CASE statements to explicitly create the order. SQL works with columns at a time, not rows. &lt;BR /&gt;&lt;BR /&gt;Did my previous solution not work? If so, how did it not work?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This will sort your times. &lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;call sort (time1, time2, time3);&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Aug 2019 17:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Find-the-median-of-three-times-not-min-max/m-p/582912#M165876</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-21T17:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL: Find the median of three times, not min/max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Find-the-median-of-three-times-not-min-max/m-p/582915#M165879</link>
      <description>&lt;P&gt;Yeah it just didn't work and changing from long to wide format still leaves me to tackle the sorting/finding difference issue. I'll try your first solution again.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also got this error when running your current solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;17061 data t5;
17062 set t4;
17063 call sort (T1, T2, T3);
----
251
ERROR 251-185: The subroutine SORT is unknown, or cannot be accessed. Check your spelling.
Either it was not found in the path(s) of executable images, or there was incorrect
or missing subroutine descriptor information.&lt;BR /&gt;&lt;BR /&gt;17064&lt;BR /&gt;17065 run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Aug 2019 17:45:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Find-the-median-of-three-times-not-min-max/m-p/582915#M165879</guid>
      <dc:creator>jerrylshen</dc:creator>
      <dc:date>2019-08-21T17:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL: Find the median of three times, not min/max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Find-the-median-of-three-times-not-min-max/m-p/582918#M165881</link>
      <description>&lt;P&gt;CALL SORT only runs on the CAS server, which obviously is not where you are trying to run this.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Does not the MEDIAN() function work in this situation?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 18:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Find-the-median-of-three-times-not-min-max/m-p/582918#M165881</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-21T18:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL: Find the median of three times, not min/max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Find-the-median-of-three-times-not-min-max/m-p/582922#M165882</link>
      <description>Sorry, its CALL SORTN() and CALL SORTC() for numeric and character.</description>
      <pubDate>Wed, 21 Aug 2019 18:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Find-the-median-of-three-times-not-min-max/m-p/582922#M165882</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-21T18:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL: Find the median of three times, not min/max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Find-the-median-of-three-times-not-min-max/m-p/582964#M165899</link>
      <description>&lt;P&gt;Yup, thanks!&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I used sortc(Time1, Time2, Time3) and then just manually find the difference of each interval, taking into account if a Time is null in a data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 19:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-Find-the-median-of-three-times-not-min-max/m-p/582964#M165899</guid>
      <dc:creator>jerrylshen</dc:creator>
      <dc:date>2019-08-21T19:44:16Z</dc:date>
    </item>
  </channel>
</rss>

