<?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 first ID and the first drug name by prescription date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/identify-first-ID-and-the-first-drug-name-by-prescription-date/m-p/936401#M368072</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by id drug_name descending prescription_dt; 
run;

data want;
set have;
by id drug_name;
if first.drug_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 Jul 2024 16:39:06 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-07-19T16:39:06Z</dc:date>
    <item>
      <title>identify first ID and the first drug name by prescription date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/identify-first-ID-and-the-first-drug-name-by-prescription-date/m-p/936391#M368070</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I want to identify the first record and first drug by the prescription date for each individual by ID. Here is a sample dataset and my intended output. Thanks&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have (index=(ID));
  input ID $ 1-7 prescrpt_dt drug_name $ 18-30  ;
  format prescrpt_dt date.;
  informat prescrpt_dt date.;
  datalines; 
1685609	6-Sep-16	ACETAZOLAMIDE
1866294	25-Nov-20	LAMOTRIGINE
1866294	20-Apr-17	TOPAMAX
1866294	1-Aug-17	TOPAMAX
1866294	20-Oct-17	TOPAMAX
1866294	8-Feb-18	TOPAMAX
1866294	15-Nov-16	TOPIRAMATE
1866294	25-Nov-16	TOPIRAMATE
1866294	19-Apr-18	TOPIRAMATE
1866294	12-Jun-18	TOPIRAMATE
1866294	4-Dec-19	TOPIRAMATE
2291100	12-Mar-22	LEVETIRACETAM
2329497	10-Apr-23	LEVETIRACETAM
2329497	9-Jul-23	LEVETIRACETAM
2329497	7-Oct-23	LEVETIRACETAM
2329497	5-Jan-24	LEVETIRACETAM
2388002	26-Apr-19	LAMOTRIGINE
2388002	8-Jul-19	LAMOTRIGINE
2388002	6-Oct-19	LAMOTRIGINE
2388002	6-Jan-20	LAMOTRIGINE
2388002	6-Apr-20	LAMOTRIGINE
2388002	4-Jul-20	LAMOTRIGINE
2388002	2-Oct-20	LAMOTRIGINE
2388002	11-Dec-20	LAMOTRIGINE
2388002	11-Mar-21	LAMOTRIGINE
2388002	9-Jun-21	LAMOTRIGINE
2388002	7-Sep-21	LAMOTRIGINE
2388002	7-Dec-21	LAMOTRIGINE
2388002	6-Mar-22	LAMOTRIGINE
2388002	4-Jun-22	LAMOTRIGINE
2388002	2-Sep-22	LAMOTRIGINE
2388002	28-Nov-22	LAMOTRIGINE
2388002	28-Feb-23	LAMOTRIGINE
2388002	27-May-23	LAMOTRIGINE
2388002	25-Aug-23	LAMOTRIGINE
2388002	23-Nov-23	LAMOTRIGINE
2388002	4-Feb-19	LEVETIRACETAM
2480879	2-Jul-23	LAMOTRIGINE
2480879	16-Oct-23	LAMOTRIGINE
2480879	22-Dec-23	LAMOTRIGINE
2480879	2-Jul-23	LEVETIRACETAM
2480879	15-Oct-23	LEVETIRACETAM
2480879	22-Dec-23	LEVETIRACETAM
;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For example: &lt;CODE class=""&gt;1866294 &lt;/CODE&gt;I sorted the data so I can have the last drug name by id and remove duplicates but my coding is not doing what i want.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sort data=have;
by id drug_name descending prescription_dt; 
run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by id drug_name;&lt;BR /&gt;if first.id and first.drug_name;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Output&lt;/P&gt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gt;&lt;TD&gt;&lt;P&gt;2388002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;23-Nov-23&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;LAMOTRIGINE&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2388002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;4-Feb-19&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;LEVETIRACETAM&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2480879&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;22-Dec-23&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;LAMOTRIGINE&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2480879&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;22-Dec-23&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;LEVETIRACETAM&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 19 Jul 2024 15:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/identify-first-ID-and-the-first-drug-name-by-prescription-date/m-p/936391#M368070</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2024-07-19T15:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: identify first ID and the first drug name by prescription date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/identify-first-ID-and-the-first-drug-name-by-prescription-date/m-p/936401#M368072</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by id drug_name descending prescription_dt; 
run;

data want;
set have;
by id drug_name;
if first.drug_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jul 2024 16:39:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/identify-first-ID-and-the-first-drug-name-by-prescription-date/m-p/936401#M368072</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-07-19T16:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: identify first ID and the first drug name by prescription date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/identify-first-ID-and-the-first-drug-name-by-prescription-date/m-p/936408#M368076</link>
      <description>&lt;P&gt;This is the sort of thing PROC SUMMARY does, in a single pass of the data, with no need to sort:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway ;
  class ID  drug_name;
  var prescrpt_dt;
  output out=want (drop=_type_) max=max_dt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2024 18:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/identify-first-ID-and-the-first-drug-name-by-prescription-date/m-p/936408#M368076</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-07-19T18:47:47Z</dc:date>
    </item>
  </channel>
</rss>

