<?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: finding index date of treatment in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/836089#M36015</link>
    <description>dates</description>
    <pubDate>Fri, 30 Sep 2022 14:47:20 GMT</pubDate>
    <dc:creator>Banke</dc:creator>
    <dc:date>2022-09-30T14:47:20Z</dc:date>
    <item>
      <title>finding index date of treatment</title>
      <link>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/835975#M36006</link>
      <description>&lt;P&gt;Hello everyone, I would like to use sql to get distinct observations for each patient that corresponds to their earliest fill date. I saw the attached code on the forum but it does not give the output as distinct observations. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/**what i have***/&lt;/P&gt;
&lt;P&gt;patient ID&amp;nbsp; &amp;nbsp; fill_date&lt;/P&gt;
&lt;P&gt;patient 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 02/23/2001&lt;/P&gt;
&lt;P&gt;patient 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 02/25/2001&lt;/P&gt;
&lt;P&gt;patient 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 03/14/2003&lt;/P&gt;
&lt;P&gt;patient 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/2006&lt;/P&gt;
&lt;P&gt;patient 2&amp;nbsp; &amp;nbsp; &amp;nbsp; 10/14/2001&lt;/P&gt;
&lt;P&gt;patient 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08/25/2008&lt;/P&gt;
&lt;P&gt;patient 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07/14/2004&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/**what i want**/&lt;/P&gt;
&lt;P&gt;patient ID&amp;nbsp; &amp;nbsp; fill_date&lt;/P&gt;
&lt;P&gt;patient 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 02/23/2001&lt;/P&gt;
&lt;P&gt;patient 2&amp;nbsp; &amp;nbsp; &amp;nbsp; 10/14/2001&lt;/P&gt;
&lt;P&gt;patient 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07/14/2004&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *
from have
group by PATIENT_ID, FILL_DATE
having FILL_DATE = MIN (FILL_DATE) ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Sep 2022 23:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/835975#M36006</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2022-09-29T23:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: finding index date of treatment</title>
      <link>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/835977#M36007</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table want as
select * 
from have
group by PATIENT_ID
having FILL_DATE = MIN (FILL_DATE) ;
quit;
&lt;/PRE&gt;
&lt;P&gt;When you have Group by Patient_id, Fill_date you have told SQL that combinations of Patient and date are what the Min is calculated from. In the example that means the Min of each date, not each patient&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 23:57:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/835977#M36007</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-29T23:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: finding index date of treatment</title>
      <link>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/835978#M36008</link>
      <description>&lt;P&gt;Thank you, it gives me more observation than i started with (750,758), and a caution in my log as shown&lt;/P&gt;
&lt;PRE&gt; proc sql;
56   create table XX as
57   select *
58   from YY
59   group by PATIENT_ID
60   having FILL_DATE = MIN (FILL_DATE) ;
NOTE: The query requires remerging summary statistics back with the original data.
NOTE: Table WORK.XX created, with 1963821 rows and 7 columns.

61   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           5.70 seconds
      cpu time            5.33 seconds
&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Sep 2022 00:04:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/835978#M36008</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2022-09-30T00:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: finding index date of treatment</title>
      <link>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/835983#M36009</link>
      <description>&lt;P&gt;I doubt it (unless perhaps YY is actually a reference to a dataset (table) in some external database that does strange things).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example try this query whose form matches yours.&lt;/P&gt;
&lt;PRE&gt;685  proc sql;
686  create table class as select * from sashelp.class;
NOTE: Table WORK.CLASS created, with 19 rows and 5 columns.

687  create table youngest as select * from class group by sex having age=min(age);
NOTE: The query requires remerging summary statistics back with the original data.
NOTE: Table WORK.YOUNGEST created, with 2 rows and 5 columns.

&lt;/PRE&gt;
&lt;P&gt;Now you might get more observations than there are patients if there are multiple observations for a patient that tie for the earliest date.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 01:41:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/835983#M36009</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-30T01:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: finding index date of treatment</title>
      <link>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/835985#M36010</link>
      <description>&lt;P&gt;If you just want the earliest date then tell SQL that fact.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table want as
select PATIENT_ID
     , min(FILL_DATE) as INDEX_DATE format=yymmdd10.
from have
group by PATIENT_ID
;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Sep 2022 01:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/835985#M36010</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-30T01:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: finding index date of treatment</title>
      <link>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/836009#M36012</link>
      <description>&lt;P&gt;Your dates are dates, not strings looking like dates?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 06:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/836009#M36012</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-09-30T06:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: finding index date of treatment</title>
      <link>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/836088#M36014</link>
      <description>This worked</description>
      <pubDate>Fri, 30 Sep 2022 14:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/836088#M36014</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2022-09-30T14:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: finding index date of treatment</title>
      <link>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/836089#M36015</link>
      <description>dates</description>
      <pubDate>Fri, 30 Sep 2022 14:47:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/finding-index-date-of-treatment/m-p/836089#M36015</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2022-09-30T14:47:20Z</dc:date>
    </item>
  </channel>
</rss>

