<?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: Identify cases using first and retain in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Identify-cases-using-first-and-retain/m-p/178641#M45604</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With the conditions you mentioned, there will be no output. The output you are expecting is having different dx i.e. diagnosis. But u mentioned it should be same diagnosis from third doctor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you really want to have same dx or just same patient, third doctor and same specialty only....?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please correct me if i missed something...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Dec 2013 12:56:52 GMT</pubDate>
    <dc:creator>JatinBansal</dc:creator>
    <dc:date>2013-12-20T12:56:52Z</dc:date>
    <item>
      <title>Identify cases using first and retain</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Identify-cases-using-first-and-retain/m-p/178639#M45602</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've a dataset sorted by patient ID (PID), diagnosis code (dx), doctor specialty code (specialty), and service date (date) in descending order, and doctor ID (docID).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to identify patients seeking more than second opinion of doctor for the same diagnosis and from doctors with the same specialty -- that is, seeing a third doctor of the same specialty -- prior to the the most doctor visit. A patient might go back and forth to different doctors.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The data is collected between January 1, 2011 and June 30, 2012. There is no date restriction except that the most recent visit within the same dx and specialty (or first record) should take place April 1, 2012.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here are the data and SAS code to read in the data (a fiscal year variable fyear is calculated (going by April 1 as the start of a fiscal year):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data dat; input&lt;/P&gt;&lt;P&gt;PiD 1 Date $ 3-10 DocID 12-14 Fee_Code $ 16-19 Specialty 21-22 Dx 24-26 Amount 28-30 Notes $ 32-76;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 20120501 101 A585 28 289&amp;nbsp; 60 1st doc w/n same PID, specialty code, dx code&lt;/P&gt;&lt;P&gt;1 20120322 101 A585 28 289&amp;nbsp; 60 1st doc&lt;/P&gt;&lt;P&gt;1 20120313 102 A585 28 289&amp;nbsp; 60 2nd doc&lt;/P&gt;&lt;P&gt;1 20120306 101 A585 28 289&amp;nbsp; 60 1st doc&lt;/P&gt;&lt;P&gt;1 20110830 111 A585 28 300&amp;nbsp; 60 3rd doc w/n same PID, specialty code, dx code&lt;/P&gt;&lt;P&gt;1 20110524 101 A585 28 289&amp;nbsp; 60 &lt;/P&gt;&lt;P&gt;1 20110420 101 A585 28 289&amp;nbsp; 60 &lt;/P&gt;&lt;P&gt;1 20110411 101 A585 28 289&amp;nbsp; 60 &lt;/P&gt;&lt;P&gt;1 20110101 101 A585 28 289&amp;nbsp; 60 &lt;/P&gt;&lt;P&gt;1 20120515 104 A401 40 110 100 1st doc w/n same PID, specialty code, dx code&lt;/P&gt;&lt;P&gt;1 20120303 105 A401 40 110 100 2nd doc&lt;/P&gt;&lt;P&gt;1 20120101 104 A401 40 110 100 1st doc&lt;/P&gt;&lt;P&gt;2 20120101 101 A303 15 305&amp;nbsp; 30 1st doc but 1st record date &amp;lt; April 1, 2012&lt;/P&gt;&lt;P&gt;2 20111130 105 A303 15 305&amp;nbsp; 50 2nd doc&lt;/P&gt;&lt;P&gt;2 20111009 108 A303 15 305&amp;nbsp; 30 3rd doc&lt;/P&gt;&lt;P&gt;2 20110707 103 A303 15 305&amp;nbsp; 30 &lt;/P&gt;&lt;P&gt;3 20120415 201 A220 30 211 116 1st doc w/n same PID, specialty code, dx code&lt;/P&gt;&lt;P&gt;3 20120401 205 A220 30 211 116 2nd doc&lt;/P&gt;&lt;P&gt;3 20120303 201 A220 30 211 116 1st doc&lt;/P&gt;&lt;P&gt;3 20111231 205 A220 30 211 116 2nd doc&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data dat (rename=(Date2=Date)); format PID Date2 Fyear; set dat;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; format Date2 yymmdd10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date2=input(date,yymmdd10.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fyear = year(intnx("YEAR.4",Date2,0));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop date;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;(The dataset "dat" is attached as well).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Based on the above mentioned criteria, only PID=1 and specialty=28 and DX=289 should be outputted because there is a third visit to DocID=111 on Aug 30, 2011. &lt;/P&gt;&lt;P&gt;PID=1, speciatlty=40, DX=110: there are 3 visits but only to 2 different doctors&lt;/P&gt;&lt;P&gt;PID=2: there are 4 visits to 3 different doctors but the most recent visit took place in January 2010, which is fiscal year 2011 (&amp;lt; April 1, 2012)&lt;/P&gt;&lt;P&gt;PID=3: there are 4 visits but to 2 different doctors&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So thte data output should look like:&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 408px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl65" height="34" width="77"&gt;PiD&lt;/TD&gt;&lt;TD class="xl65" width="64"&gt;Specialty&lt;/TD&gt;&lt;TD class="xl65" width="64"&gt;Dx&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl66" height="20" width="77"&gt;1&lt;/TD&gt;&lt;TD class="xl66" width="64"&gt;28&lt;/TD&gt;&lt;TD class="xl66" width="64"&gt;289&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I assume I should carry docID to the next record to compare and see if they are identical, but I need to compare not just the preceding one but all the preceding ones. I could transpose and compare docID1, docID2, docID3....., but I could have many records due to many visit entries (not manageable, just not preferable if I had other solutions).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help you could provide.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Dec 2013 23:00:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Identify-cases-using-first-and-retain/m-p/178639#M45602</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2013-12-19T23:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: Identify cases using first and retain</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Identify-cases-using-first-and-retain/m-p/178640#M45603</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;On second thought,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once I get rid of cases with first record's date &amp;lt; April 1, 2012, I think I could have just use Proc SQL or Proc SORT nodupkey to first keep unique records of PID, specialty and DX, docID and then count # of docID. If it's &amp;gt;=3, then there is a visit to a third doctor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I'd like to rephrase my questions so that I have to use RETAIN to read down the data and compare preceding records (if possible) - that is what if I'd like to identify only cases with a visit to a third doctor that is within a year prior to the most recent visit date. The output should still be the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Dec 2013 23:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Identify-cases-using-first-and-retain/m-p/178640#M45603</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2013-12-19T23:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Identify cases using first and retain</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Identify-cases-using-first-and-retain/m-p/178641#M45604</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With the conditions you mentioned, there will be no output. The output you are expecting is having different dx i.e. diagnosis. But u mentioned it should be same diagnosis from third doctor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you really want to have same dx or just same patient, third doctor and same specialty only....?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please correct me if i missed something...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 12:56:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Identify-cases-using-first-and-retain/m-p/178641#M45604</guid>
      <dc:creator>JatinBansal</dc:creator>
      <dc:date>2013-12-20T12:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: Identify cases using first and retain</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Identify-cases-using-first-and-retain/m-p/178642#M45605</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for replying. The third doctor has to be from the same specialty for the same DX of the patient. So yes it has to be under the same patient, same patient's dx and same specialty of doctor.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 16:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Identify-cases-using-first-and-retain/m-p/178642#M45605</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2013-12-20T16:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Identify cases using first and retain</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Identify-cases-using-first-and-retain/m-p/178643#M45606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok so first off you want to take only those cases who meet your first criteria which is the first visit was after April 1, 2012. For reference the dataset you put out doesn't have anyone who meets that criteria, but you can run this code to take out all of the other people (I specify in the below code that the date is April 1, 2012.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table um2 as&lt;/P&gt;&lt;P&gt;select distinct PID, date, docid, specialty, dx, fyear, (max(date)) format=mmddyy10. as last_dt /*You specify what the most recent date was so you can compare to it in the next step*/&lt;/P&gt;&lt;P&gt;from dat&lt;/P&gt;&lt;P&gt;group by PID&lt;/P&gt;&lt;P&gt;having (min(date)&amp;gt;'01Apr2012'd); /*Here you specify that the first visit for the PID has to have occurred after this date (April 1, 2012) and remove all PID who do not meet this criteria*/&lt;/P&gt;&lt;P&gt;create table um3 as&lt;/P&gt;&lt;P&gt;select distinct PID, docid, dx, specialty /*Since you now know what the most recent visit date is, you can specify that the visit that you are counting had to have occurred within a specific time frame, in this case 1 year or 365 days. I wrote it that the most recent date is first so you have to specify datdif to be negative, but you could reverse it. Also I included 0, so the last visit is counted*/&lt;/P&gt;&lt;P&gt;from um2&lt;/P&gt;&lt;P&gt;where datdif(last_dt, date, 'act/act') between -365 and 0;&lt;/P&gt;&lt;P&gt;create table um4 as /*since you have eliminated all of the visits which didn't occur within 1 year you now can reduce your visits based on dx and specialty, and count the number of DocID's that are in the table for each PID*/&lt;/P&gt;&lt;P&gt;select distinct PID, dx, specialty, (count(docid)) as count&lt;/P&gt;&lt;P&gt;from um3&lt;/P&gt;&lt;P&gt;group by pid, dx, specialty; &lt;/P&gt;&lt;P&gt;create table cohort as&lt;/P&gt;&lt;P&gt;select distinct pid, dx, specialty&lt;/P&gt;&lt;P&gt;from um4&lt;/P&gt;&lt;P&gt;where count &amp;gt;=3; /*This line could have been specified in um4 as having count &amp;gt;=3 or it can be written as another line. This specification will give you only those PID who had at least 3 visits to different docids in the year preceding the most recent visit for the same dx and in the same specialty*/&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code should create the cohort that you have so far specified.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 21:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Identify-cases-using-first-and-retain/m-p/178643#M45606</guid>
      <dc:creator>overmar</dc:creator>
      <dc:date>2013-12-20T21:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: Identify cases using first and retain</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Identify-cases-using-first-and-retain/m-p/178644#M45607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why would you sort by descending service date?&amp;nbsp; That makes it impossible for a DATA step to do the work.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you have any control over the sorted order to the data?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Dec 2013 22:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Identify-cases-using-first-and-retain/m-p/178644#M45607</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-12-20T22:40:53Z</dc:date>
    </item>
  </channel>
</rss>

