<?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: Data Quality Check: How to check that age increases or stays the same across visits in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-Quality-Check-How-to-check-that-age-increases-or-stays-the/m-p/726593#M225793</link>
    <description>&lt;P&gt;Thank you so much! This worked perfectly!&lt;/P&gt;</description>
    <pubDate>Tue, 16 Mar 2021 00:23:22 GMT</pubDate>
    <dc:creator>awardell</dc:creator>
    <dc:date>2021-03-16T00:23:22Z</dc:date>
    <item>
      <title>Data Quality Check: How to check that age increases or stays the same across visits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Quality-Check-How-to-check-that-age-increases-or-stays-the/m-p/726428#M225709</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on a data set that has PatientID, Visit_Date, and Age. I need to check data quality by flagging those who have a decrease in age from an earlier visit_date to a later visit_date, as this is not possible. My data set looks like the following example:&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;PatientID&lt;/TD&gt;&lt;TD&gt;Visit_Date&lt;/TD&gt;&lt;TD&gt;Age&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1/2/2003&lt;/TD&gt;&lt;TD&gt;25&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;2/4/2005&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;23&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3/7/2006&lt;/TD&gt;&lt;TD&gt;26&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3/8/2003&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;5/12/2004&lt;/TD&gt;&lt;TD&gt;51&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;5/13/2005&lt;/TD&gt;&lt;TD&gt;52&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;5/14/2006&lt;/TD&gt;&lt;TD&gt;53&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;4/6/2020&lt;/TD&gt;&lt;TD&gt;72&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;12/7/2020&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;65&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where observations in PatientID 1 and 3 would need to be flagged. How should I go about doing this? Could I use the lag function? I am fairly unfamiliar with the lag function, so any help would be greatly appreciated! Thank you in advance!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 15:19:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Quality-Check-How-to-check-that-age-increases-or-stays-the/m-p/726428#M225709</guid>
      <dc:creator>awardell</dc:creator>
      <dc:date>2021-03-15T15:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Data Quality Check: How to check that age increases or stays the same across visits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Quality-Check-How-to-check-that-age-increases-or-stays-the/m-p/726434#M225713</link>
      <description>&lt;P&gt;One way using DIF function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data want;
   set have;
   ageflag = (dif(age)&amp;lt;0);
   by patientid;
   if first.patientid then ageflag=.;
run;&lt;/PRE&gt;
&lt;P&gt;DIF returns current value - value on previous record. SAS will return 1 for true and 0 for false, so the comparison will set a flag of 1 when the value on the current record is less than for the previous.&lt;/P&gt;
&lt;P&gt;Since you wouldn't want to compare one patient's age with another patient then the first patientid sets the flag to missing (could use 0 but missing is more appropriate in many cases).&lt;/P&gt;
&lt;P&gt;The above solution assumes the data is sorted by patientid and date of visit.&lt;/P&gt;
&lt;P&gt;If not sorted by patientid but grouped you could use NOTSORTED on the BY patientid statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DIF is closely related to LAG but since it is very common to do what you requested, the difference between current and previous, SAS supplies the DIF function as well.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 15:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Quality-Check-How-to-check-that-age-increases-or-stays-the/m-p/726434#M225713</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-15T15:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: Data Quality Check: How to check that age increases or stays the same across visits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Quality-Check-How-to-check-that-age-increases-or-stays-the/m-p/726593#M225793</link>
      <description>&lt;P&gt;Thank you so much! This worked perfectly!&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 00:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Quality-Check-How-to-check-that-age-increases-or-stays-the/m-p/726593#M225793</guid>
      <dc:creator>awardell</dc:creator>
      <dc:date>2021-03-16T00:23:22Z</dc:date>
    </item>
  </channel>
</rss>

