<?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: Keep only value and date that occurred before or at last visit date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Keep-only-value-and-date-that-occurred-before-or-at-last-visit/m-p/926231#M41573</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464169"&gt;@tan-wongv&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you so much for your response!&amp;nbsp; I tried this code but the outcome just showed the observation where recorded_time is less than last_vist. It did not include the recorded_time that is equal to last_visit.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That could only happen if the date values are not integers.&amp;nbsp; The DATE format will ignore fractions of a day so the values would print as being equal even though they would compare as not equal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try looking at the values for one of the cases where the values look to you like they are equal but did not get selected by the WHERE (or IF) test.&amp;nbsp; Display the values with out the format or with some other format such as BEST32. or HEX16.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How did you enter those values into your SAS dataset?&lt;/P&gt;</description>
    <pubDate>Sun, 28 Apr 2024 23:07:55 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-04-28T23:07:55Z</dc:date>
    <item>
      <title>Keep only value and date that occurred before or at last visit date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keep-only-value-and-date-that-occurred-before-or-at-last-visit/m-p/926221#M41568</link>
      <description>&lt;P&gt;I have a dataset contains DMRN, last visit date, the presence of UI, and recorded date of UI&lt;/P&gt;
&lt;TABLE style="width: 50px;" border="1" width="50"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;DMRN&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;last_visit&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;UI&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;recorded_time&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;31&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;26AUG2021&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;06APR2018&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;31&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;26AUG2021&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;16JAN2020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;31&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;26AUG2021&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;4MAY2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;&lt;STRONG&gt;31&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;&lt;STRONG&gt;26AUG2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;&lt;STRONG&gt;26MAY2022&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;33&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;24MAY2022&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;02MAR2020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;33&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;24MAY2022&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;24MAY2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;35&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;01DEC2014&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;25MAR2013&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;&lt;STRONG&gt;35&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;&lt;STRONG&gt;01DEC2014&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;&lt;STRONG&gt;05JAN2015&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to keep only UI value and recorded_time that occurred before or equal to last_visit date for each DMRN. Could you please help me with the code?The outcome would look like this:&lt;/P&gt;
&lt;TABLE style="width: 50px;" border="1" width="311px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="58.7969px"&gt;DMRN&lt;/TD&gt;
&lt;TD width="100.703px"&gt;last_visit&lt;/TD&gt;
&lt;TD width="40px"&gt;UI&lt;/TD&gt;
&lt;TD width="113.344px"&gt;recorded_time&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px"&gt;31&lt;/TD&gt;
&lt;TD width="100.703px"&gt;26AUG2021&lt;/TD&gt;
&lt;TD width="40px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px"&gt;06APR2018&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px"&gt;31&lt;/TD&gt;
&lt;TD width="100.703px"&gt;26AUG2021&lt;/TD&gt;
&lt;TD width="40px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px"&gt;16JAN2020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px"&gt;31&lt;/TD&gt;
&lt;TD width="100.703px"&gt;26AUG2021&lt;/TD&gt;
&lt;TD width="40px"&gt;1&lt;/TD&gt;
&lt;TD width="113.344px"&gt;4MAY2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px"&gt;33&lt;/TD&gt;
&lt;TD width="100.703px"&gt;24MAY2022&lt;/TD&gt;
&lt;TD width="40px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px"&gt;02MAR2020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px"&gt;33&lt;/TD&gt;
&lt;TD width="100.703px"&gt;24MAY2022&lt;/TD&gt;
&lt;TD width="40px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px"&gt;24MAY2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px"&gt;35&lt;/TD&gt;
&lt;TD width="100.703px"&gt;01DEC2014&lt;/TD&gt;
&lt;TD width="40px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px"&gt;25MAR2013&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Sun, 28 Apr 2024 18:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keep-only-value-and-date-that-occurred-before-or-at-last-visit/m-p/926221#M41568</guid>
      <dc:creator>tan-wongv</dc:creator>
      <dc:date>2024-04-28T18:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only value and date that occurred before or at last visit date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keep-only-value-and-date-that-occurred-before-or-at-last-visit/m-p/926224#M41570</link>
      <description>&lt;P&gt;Seems simple enough.&amp;nbsp; First let's convert your existing (HAVE) data listing and expected (EXPECT) data listings into datasets.&amp;nbsp; Then you just need to select the observations where recorded_time is less than or equal to last_visit.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input DMRN $ last_visit :date. UI recorded_time :date.;
  format last_visit recorded_time date9.;
cards;
31 26AUG2021 0 06APR2018
31 26AUG2021 0 16JAN2020
31 26AUG2021 1 4MAY2021
31 26AUG2021 1 26MAY2022
33 24MAY2022 0 02MAR2020
33 24MAY2022 0 24MAY2022
35 01DEC2014 0 25MAR2013
35 01DEC2014 1 05JAN2015
;

data expect;
  input DMRN $ last_visit :date. UI recorded_time :date.;
  format last_visit recorded_time date9.;
cards;
31 26AUG2021 0 06APR2018
31 26AUG2021 0 16JAN2020
31 26AUG2021 1 4MAY2021
33 24MAY2022 0 02MAR2020
33 24MAY2022 0 24MAY2022
35 01DEC2014 0 25MAR2013
;

data want ;
  set have;
  where recorded_time &amp;lt;= last_visit;
run;

proc compare data=want compare=expect;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1714329161689.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95982i9FA824C6544F20A6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1714329161689.png" alt="Tom_0-1714329161689.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Apr 2024 18:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keep-only-value-and-date-that-occurred-before-or-at-last-visit/m-p/926224#M41570</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-28T18:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only value and date that occurred before or at last visit date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keep-only-value-and-date-that-occurred-before-or-at-last-visit/m-p/926230#M41572</link>
      <description>&lt;P&gt;Thank you so much for your response!&amp;nbsp; I tried this code but the outcome just showed the observation where recorded_time is less than last_vist. It did not include the recorded_time that is equal to last_visit.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Apr 2024 23:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keep-only-value-and-date-that-occurred-before-or-at-last-visit/m-p/926230#M41572</guid>
      <dc:creator>tan-wongv</dc:creator>
      <dc:date>2024-04-28T23:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only value and date that occurred before or at last visit date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keep-only-value-and-date-that-occurred-before-or-at-last-visit/m-p/926231#M41573</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464169"&gt;@tan-wongv&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you so much for your response!&amp;nbsp; I tried this code but the outcome just showed the observation where recorded_time is less than last_vist. It did not include the recorded_time that is equal to last_visit.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That could only happen if the date values are not integers.&amp;nbsp; The DATE format will ignore fractions of a day so the values would print as being equal even though they would compare as not equal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try looking at the values for one of the cases where the values look to you like they are equal but did not get selected by the WHERE (or IF) test.&amp;nbsp; Display the values with out the format or with some other format such as BEST32. or HEX16.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How did you enter those values into your SAS dataset?&lt;/P&gt;</description>
      <pubDate>Sun, 28 Apr 2024 23:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keep-only-value-and-date-that-occurred-before-or-at-last-visit/m-p/926231#M41573</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-28T23:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only value and date that occurred before or at last visit date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keep-only-value-and-date-that-occurred-before-or-at-last-visit/m-p/926233#M41574</link>
      <description>&lt;P&gt;Thank you so much for your guide!! I found the problem as you said. I fixed it and now your code works &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Apr 2024 23:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keep-only-value-and-date-that-occurred-before-or-at-last-visit/m-p/926233#M41574</guid>
      <dc:creator>tan-wongv</dc:creator>
      <dc:date>2024-04-28T23:38:50Z</dc:date>
    </item>
  </channel>
</rss>

