<?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: Trying to compare multiple records for the same ID across years in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-compare-multiple-records-for-the-same-ID-across-years/m-p/163225#M42361</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;"&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;but the output file was &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;identical&lt;/STRONG&gt;&lt;/SPAN&gt; to the input file". &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;Are you sure?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 13 Feb 2015 23:59:17 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2015-02-13T23:59:17Z</dc:date>
    <item>
      <title>Trying to compare multiple records for the same ID across years</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-compare-multiple-records-for-the-same-ID-across-years/m-p/163222#M42358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to identify kids with asthma who have received a new delivery device for their medication across years (the measurement year and the year prior to the measurement year).&amp;nbsp; The problem occurs when a kid has more than 1 type of delivery device (there are 5 categories of devices).&amp;nbsp; Consider the example data:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 353px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl63" height="19" width="72"&gt;ID&lt;/TD&gt;&lt;TD class="xl63" width="107"&gt;device_measyr&lt;/TD&gt;&lt;TD class="xl63" width="98"&gt;device_yrprior&lt;/TD&gt;&lt;TD class="xl63" width="76"&gt;newdevice&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="19"&gt;5626&lt;/TD&gt;&lt;TD class="xl63"&gt;2&lt;/TD&gt;&lt;TD class="xl63"&gt;4&lt;/TD&gt;&lt;TD class="xl63"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="19"&gt;7559&lt;/TD&gt;&lt;TD class="xl63"&gt;1&lt;/TD&gt;&lt;TD class="xl63"&gt;4&lt;/TD&gt;&lt;TD class="xl63"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="19"&gt;7559&lt;/TD&gt;&lt;TD class="xl63"&gt;4&lt;/TD&gt;&lt;TD class="xl63"&gt;1&lt;/TD&gt;&lt;TD class="xl63"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="19"&gt;8230&lt;/TD&gt;&lt;TD class="xl63"&gt;1&lt;/TD&gt;&lt;TD class="xl63"&gt;2&lt;/TD&gt;&lt;TD class="xl63"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="19"&gt;8230&lt;/TD&gt;&lt;TD class="xl63"&gt;1&lt;/TD&gt;&lt;TD class="xl63"&gt;4&lt;/TD&gt;&lt;TD class="xl63"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="19"&gt;8230&lt;/TD&gt;&lt;TD class="xl63"&gt;2&lt;/TD&gt;&lt;TD class="xl63"&gt;4&lt;/TD&gt;&lt;TD class="xl63"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="19"&gt;8230&lt;/TD&gt;&lt;TD class="xl63"&gt;4&lt;/TD&gt;&lt;TD class="xl63"&gt;2&lt;/TD&gt;&lt;TD class="xl63"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ID# 5626 only had 1 device, and it was different across years.&amp;nbsp; So that kid really did get a new device in the measurement year, and newdevice should = 1.&amp;nbsp; But 7559 had a 1 and a 4 in the year prior, and a 1 and a 4 in the meas year, so 7559 is not a valid case and should be deleted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;8230 is a little more complicated.&amp;nbsp; This kid had 2 and 4 in both years, but had 1 in the meas year ONLY.&amp;nbsp; Therefore 8230 is a valid case, and newdevice should = 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I should note that the individual records don't matter -- if a kid got ANY new device in the meas year, then that ID should be retained.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems like this should be pretty easy using PROC SQL to select distinct IDs, but I'm not quite sure how to get it to compare all values for all records for each ID.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 15:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-compare-multiple-records-for-the-same-ID-across-years/m-p/163222#M42358</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2015-02-11T15:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare multiple records for the same ID across years</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-compare-multiple-records-for-the-same-ID-across-years/m-p/163223#M42359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understood what you mean, But I prefer to Hash Table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
input ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;device_measyr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;device_yrprior;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
cards;
5626&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
7559&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
7559&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
8230&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
8230&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
8230&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
8230&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2
;
run;
proc sql;
 create table want as
&amp;nbsp; select *,
case when count(*)=1 then 1
 when exists(select * from have&amp;nbsp; where id=a.id and device_measyr not in (select device_yrprior from have where id=a.id )) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then 1 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else 0 
end as newdevice
&amp;nbsp;&amp;nbsp; from have as a
&amp;nbsp;&amp;nbsp;&amp;nbsp; group by id ;
quit;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Feb 2015 10:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-compare-multiple-records-for-the-same-ID-across-years/m-p/163223#M42359</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-02-12T10:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare multiple records for the same ID across years</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-compare-multiple-records-for-the-same-ID-across-years/m-p/163224#M42360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately that didn't work.&amp;nbsp; It didn't produce any errors in the log, but the output file was identical to the input file.&amp;nbsp; If you prefer to use a hash table rather than Proc SQL, that's fine with me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Feb 2015 13:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-compare-multiple-records-for-the-same-ID-across-years/m-p/163224#M42360</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2015-02-13T13:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare multiple records for the same ID across years</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-compare-multiple-records-for-the-same-ID-across-years/m-p/163225#M42361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;"&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;but the output file was &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;identical&lt;/STRONG&gt;&lt;/SPAN&gt; to the input file". &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;Are you sure?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Feb 2015 23:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-compare-multiple-records-for-the-same-ID-across-years/m-p/163225#M42361</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-02-13T23:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare multiple records for the same ID across years</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-compare-multiple-records-for-the-same-ID-across-years/m-p/163226#M42362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Didn't you notice I added a new column&amp;nbsp; "&lt;STRONG&gt;newdevice&lt;/STRONG&gt;"&amp;nbsp; into it ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Feb 2015 07:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-compare-multiple-records-for-the-same-ID-across-years/m-p/163226#M42362</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-02-14T07:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare multiple records for the same ID across years</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Trying-to-compare-multiple-records-for-the-same-ID-across-years/m-p/163227#M42363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's working now!&amp;nbsp; Yes, the output file was identical to the input file.&amp;nbsp; Note that the portion of the input file that I used as an example in my original post already includes a column named "newdevice".&amp;nbsp; That's because there was an IF-THEN statement in the step that created the input file that calculated the value for newdevice for all cases that only had 1 device in the year prior.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems like the Proc SQL subroutine should have overwritten the value of newdevice for cases where there was more than 1 device, but it did not.&amp;nbsp; So I simply moved the IF-THEN statement to AFTER the Proc SQL.&amp;nbsp; So the Proc SQL took care of the case with more than 1 device, and then the IF-THEN statement took care of cases that only had 1 device.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Feb 2015 16:45:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Trying-to-compare-multiple-records-for-the-same-ID-across-years/m-p/163227#M42363</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2015-02-16T16:45:00Z</dc:date>
    </item>
  </channel>
</rss>

