<?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 Proc SQL/SAS: How to return only times that are bigger? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-How-to-return-only-times-that-are-bigger/m-p/580001#M164709</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the same subject, I want to only return the data row when Time1 &amp;gt; Time2. There's also a limit of 3 data rows for the same subject (ie there can not be 4 data rows of Subject 1 in the input data). The total size of the input data is unknown. Doesn't need to be efficient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example Data:&lt;/P&gt;&lt;P&gt;╔═════════╦═══════╦═══════╗&lt;BR /&gt;║ Subject&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ Time1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;║ Time2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;║&lt;BR /&gt;╠═════════╬═══════╬═══════╣&lt;BR /&gt;║ 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║&lt;BR /&gt;║ 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║&lt;BR /&gt;║ 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:14&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║&lt;BR /&gt;╚═════════╩═══════╩═══════╝&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this case, Time2 11:14 &amp;gt; Time1 11:13, so it doesn't get outputted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected Output:&lt;BR /&gt;╔═════════╦═══════╦═══════╗&lt;BR /&gt;║ Subject&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ Time1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;║ Time2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;║&lt;BR /&gt;╠═════════╬═══════╬═══════╣&lt;BR /&gt;║ 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║&lt;BR /&gt;║ 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║&lt;BR /&gt;╚═════════╩═══════╩═══════╝&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've brainstormed of isolating the subject where there's an instance of Time2&amp;gt;Time1 and then deleting that Subject from the output, but that would&amp;nbsp; also delete the good data rows. I also know that in SAS there's the .last and .next (or something like that) and I can just manually calculate that using a loop or something?&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm open to either proc sql/SAS advices, but I am more experienced in SQL but I can't think of a way for this.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 08 Aug 2019 21:37:26 GMT</pubDate>
    <dc:creator>jerrylshen</dc:creator>
    <dc:date>2019-08-08T21:37:26Z</dc:date>
    <item>
      <title>Proc SQL/SAS: How to return only times that are bigger?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-How-to-return-only-times-that-are-bigger/m-p/580001#M164709</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the same subject, I want to only return the data row when Time1 &amp;gt; Time2. There's also a limit of 3 data rows for the same subject (ie there can not be 4 data rows of Subject 1 in the input data). The total size of the input data is unknown. Doesn't need to be efficient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example Data:&lt;/P&gt;&lt;P&gt;╔═════════╦═══════╦═══════╗&lt;BR /&gt;║ Subject&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ Time1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;║ Time2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;║&lt;BR /&gt;╠═════════╬═══════╬═══════╣&lt;BR /&gt;║ 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║&lt;BR /&gt;║ 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║&lt;BR /&gt;║ 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:14&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║&lt;BR /&gt;╚═════════╩═══════╩═══════╝&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this case, Time2 11:14 &amp;gt; Time1 11:13, so it doesn't get outputted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected Output:&lt;BR /&gt;╔═════════╦═══════╦═══════╗&lt;BR /&gt;║ Subject&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ Time1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;║ Time2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;║&lt;BR /&gt;╠═════════╬═══════╬═══════╣&lt;BR /&gt;║ 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║&lt;BR /&gt;║ 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║ 11:12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ║&lt;BR /&gt;╚═════════╩═══════╩═══════╝&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've brainstormed of isolating the subject where there's an instance of Time2&amp;gt;Time1 and then deleting that Subject from the output, but that would&amp;nbsp; also delete the good data rows. I also know that in SAS there's the .last and .next (or something like that) and I can just manually calculate that using a loop or something?&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm open to either proc sql/SAS advices, but I am more experienced in SQL but I can't think of a way for this.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2019 21:37:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-How-to-return-only-times-that-are-bigger/m-p/580001#M164709</guid>
      <dc:creator>jerrylshen</dc:creator>
      <dc:date>2019-08-08T21:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL/SAS: How to return only times that are bigger?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-How-to-return-only-times-that-are-bigger/m-p/580002#M164710</link>
      <description>&lt;P&gt;Are your variables SAS time valued variables (numeric with a format of HHMM, TIME or TOD of some form)&amp;nbsp;or character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values are SAS time values this could be as simple as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; where time1 &amp;gt; time2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If they are not SAS time valued variables then likely create actual time valued variables and compare those.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2019 21:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-How-to-return-only-times-that-are-bigger/m-p/580002#M164710</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-08T21:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL/SAS: How to return only times that are bigger?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-How-to-return-only-times-that-are-bigger/m-p/580003#M164711</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Subject (Time1 Time2) (:time5.);
format time1 time2 time5.;
datalines;
1 11:13 11:12
1 11:15 11:12
1 11:15 11:14
;

proc sql;
select *
from have
group by subject
having time2 &amp;lt; min(time1);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                                Subject  Time1  Time2
                               ----------------------
                                      1  11:13  11:12
                                      1  11:15  11:12
&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Aug 2019 22:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-How-to-return-only-times-that-are-bigger/m-p/580003#M164711</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-08-08T22:02:12Z</dc:date>
    </item>
  </channel>
</rss>

