<?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 check chronological order of event datetimes? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709710#M218303</link>
    <description>&lt;P&gt;What does the result look like?&lt;/P&gt;
&lt;P&gt;Do you want one variable that indicates "all in order"/"not in order" or do you want 34 variables showing the comparisons of var1 to var2, var2 to var3, var3 to var4, ..., var34 to var35?&lt;/P&gt;
&lt;P&gt;And HOW are missing values actually treated? Ignored in comparisons? Always "out of order"? Out of order if other than the first (or last or some other rule)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will allow you to compare multiple variables at one time like:&amp;nbsp; v1 &amp;lt; v2 &amp;lt; v3 &amp;lt;v4&amp;lt; ...&amp;lt;v35.&lt;/P&gt;
&lt;P&gt;But if you use this the missing value is &lt;STRONG&gt;always&lt;/STRONG&gt; less than anything. So any missing other than in the left most variables the result for the total comparison will be "false". So how missing is to be treated needs to be stated explicitly. If you want pairwise comparison results then the rule for how missing needs to be provided as well as you have 3 cases to consider involving missing:&lt;/P&gt;
&lt;P&gt;Var1 missing , Var2 not missing&lt;/P&gt;
&lt;P&gt;Var1 not missing, Var2 missing&lt;/P&gt;
&lt;P&gt;Var1 missing , Var2 missing&lt;/P&gt;
&lt;P&gt;So rules involving all of these cases would be needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Jan 2021 20:50:53 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-01-06T20:50:53Z</dc:date>
    <item>
      <title>How do I check chronological order of event datetimes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709701#M218296</link>
      <description>&lt;P class="lia-align-left"&gt;Hi SAS users,&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;My dataset has 35 variables that are in SAS datetime format, for ex:&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV class="lia-align-left" align="center"&gt;16APR2019:21:22:00&lt;/DIV&gt;&lt;DIV class="lia-align-left" align="center"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-align-left" align="center"&gt;&lt;SPAN style="font-family: inherit;"&gt;I am trying to check the chronological order of these variables, where var1 occurred before var2, var 2 before var3, ...var34 before var35 for all 35 variables. For each variable, there is either a datetime value or a missing value. This needs to be done for each case ID.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-align-left" align="center"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-align-left" align="center"&gt;&lt;SPAN style="font-family: inherit;"&gt;So for case #1, I need to check that var1 occurred before var2, var 2 before var3,...var 35. Repeat for all cases.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;&lt;SPAN&gt;My goal is to flag observations if the events are not in chronological order. I am a beginner and having difficulty approaching how to do this.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-align-left" align="center"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-align-left" align="center"&gt;&lt;SPAN style="font-family: inherit;"&gt;&lt;SPAN&gt;Thank you, any help would be appreciated.&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-align-left" align="center"&gt;&lt;BR /&gt;&lt;DIV class="branch"&gt;&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 06 Jan 2021 20:27:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709701#M218296</guid>
      <dc:creator>epibio2021</dc:creator>
      <dc:date>2021-01-06T20:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I check chronological order of event datetimes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709702#M218297</link>
      <description>could you please post sample data.</description>
      <pubDate>Wed, 06 Jan 2021 20:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709702#M218297</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2021-01-06T20:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I check chronological order of event datetimes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709706#M218299</link>
      <description>&lt;P&gt;Sample Data:&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV align="center"&gt;&lt;BR /&gt;&lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Obs&lt;/TD&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;var3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;04MAY2018:13:30:00&lt;/TD&gt;&lt;TD&gt;04MAY2018:18:35:00&lt;/TD&gt;&lt;TD&gt;06MAY2018:14:07:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;04MAY2018:17:00:00&lt;/TD&gt;&lt;TD&gt;05MAY2018:00:43:00&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;09MAY2018:06:55:00&lt;/TD&gt;&lt;TD&gt;09MAY2018:12:00:00&lt;/TD&gt;&lt;TD&gt;14MAY2018:11:23:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;12MAY2018:20:00:00&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;14MAY2018:17:30:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;14MAY2018:14:00:00&lt;/TD&gt;&lt;TD&gt;14MAY2018:17:50:00&lt;/TD&gt;&lt;TD&gt;15MAY2018:11:37:00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;For each obs, I need to check that var 1 occured before var 2, and var 2 occured before var 3.&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 06 Jan 2021 20:36:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709706#M218299</guid>
      <dc:creator>epibio2021</dc:creator>
      <dc:date>2021-01-06T20:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I check chronological order of event datetimes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709709#M218302</link>
      <description>&lt;P&gt;What is the answer you want for that example input?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 20:43:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709709#M218302</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-06T20:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I check chronological order of event datetimes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709710#M218303</link>
      <description>&lt;P&gt;What does the result look like?&lt;/P&gt;
&lt;P&gt;Do you want one variable that indicates "all in order"/"not in order" or do you want 34 variables showing the comparisons of var1 to var2, var2 to var3, var3 to var4, ..., var34 to var35?&lt;/P&gt;
&lt;P&gt;And HOW are missing values actually treated? Ignored in comparisons? Always "out of order"? Out of order if other than the first (or last or some other rule)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will allow you to compare multiple variables at one time like:&amp;nbsp; v1 &amp;lt; v2 &amp;lt; v3 &amp;lt;v4&amp;lt; ...&amp;lt;v35.&lt;/P&gt;
&lt;P&gt;But if you use this the missing value is &lt;STRONG&gt;always&lt;/STRONG&gt; less than anything. So any missing other than in the left most variables the result for the total comparison will be "false". So how missing is to be treated needs to be stated explicitly. If you want pairwise comparison results then the rule for how missing needs to be provided as well as you have 3 cases to consider involving missing:&lt;/P&gt;
&lt;P&gt;Var1 missing , Var2 not missing&lt;/P&gt;
&lt;P&gt;Var1 not missing, Var2 missing&lt;/P&gt;
&lt;P&gt;Var1 missing , Var2 missing&lt;/P&gt;
&lt;P&gt;So rules involving all of these cases would be needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 20:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709710#M218303</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-06T20:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I check chronological order of event datetimes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709716#M218309</link>
      <description>&lt;P&gt;I would like one variable to indicate that chronological order is "good" or "not good".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently have the following:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if var1 &amp;lt;= var2 &amp;lt;= var3 .... &amp;lt;= var35 then CHRON = 'Good'; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As you've stated, if any of the 35 variables is missing data, CHRON returns a missing value. I would like any missing data to be ignored and skip to the next variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if var2 and var5 are missing data, I would like it to check that var1&amp;lt;var3&amp;lt;var4&amp;lt;var6 = good/not good.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 21:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709716#M218309</guid>
      <dc:creator>epibio2021</dc:creator>
      <dc:date>2021-01-06T21:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I check chronological order of event datetimes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709721#M218313</link>
      <description>&lt;P&gt;The program below compares neighboring variables.&amp;nbsp; If the, say, 6th variable is less than the 5th, then flag=6.&amp;nbsp; If all 35 variables are in non-decreasing order, then flag=0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   array dtimes {*}   var1-var35;
   do flag=2 to dim(dtimes) until(dtimes{flag}&amp;lt;dtimes{flag-1});
   end;
   if flag=dim(dtimes)+1 then flag=0;
end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that missing date values compare as less than all non-missing data values.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 21:09:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/709721#M218313</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-01-06T21:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I check chronological order of event datetimes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/800943#M315165</link>
      <description>Works for me! Thanks!</description>
      <pubDate>Tue, 08 Mar 2022 21:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-check-chronological-order-of-event-datetimes/m-p/800943#M315165</guid>
      <dc:creator>dikang77</dc:creator>
      <dc:date>2022-03-08T21:51:22Z</dc:date>
    </item>
  </channel>
</rss>

