<?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: Assigning values by comparing dates in two datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assigning-values-by-comparing-dates-in-two-datasets/m-p/315813#M68931</link>
    <description>&lt;P&gt;Thanks for help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to get the last dose taken on or before AE start date. My code worked for all obs except this obs because there are two doses taken on the day AE started. &amp;nbsp;I need to get the maximum dose taken on that day. Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 01 Dec 2016 04:51:19 GMT</pubDate>
    <dc:creator>knveraraju91</dc:creator>
    <dc:date>2016-12-01T04:51:19Z</dc:date>
    <item>
      <title>Assigning values by comparing dates in two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-values-by-comparing-dates-in-two-datasets/m-p/315767#M68927</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my datasets the following values present. my code works for all obs except these obs. Please help thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ex&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp;exdate &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;exdose&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;09MAY2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;09MAY2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ae&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; aedate &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;09MAY2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;code;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table dose as&lt;BR /&gt;select a.*,b.exdose&lt;BR /&gt;from ae as a left join EX as b&lt;BR /&gt;on a.id=b.id and a.Aedate-b.exdate &amp;gt;=0&lt;BR /&gt;group by a.id,a.aedate&lt;BR /&gt;having a.Aedate-b.exdate1=min(a.Aedate-b.exdate);&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output getting ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; aedate &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; exdose&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;09MAY2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;output need;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; aedate &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; exdose&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;09MAY2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 03:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-values-by-comparing-dates-in-two-datasets/m-p/315767#M68927</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-12-01T03:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning values by comparing dates in two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-values-by-comparing-dates-in-two-datasets/m-p/315799#M68929</link>
      <description>&lt;P&gt;Can you provide one liner how the data to be picked for the output. Is it maximum of of exdose or minimum of exdose Or is there any other logic. what condition are applied on dates?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 04:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-values-by-comparing-dates-in-two-datasets/m-p/315799#M68929</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-12-01T04:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning values by comparing dates in two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-values-by-comparing-dates-in-two-datasets/m-p/315813#M68931</link>
      <description>&lt;P&gt;Thanks for help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to get the last dose taken on or before AE start date. My code worked for all obs except this obs because there are two doses taken on the day AE started. &amp;nbsp;I need to get the maximum dose taken on that day. Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 04:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-values-by-comparing-dates-in-two-datasets/m-p/315813#M68931</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-12-01T04:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning values by comparing dates in two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-values-by-comparing-dates-in-two-datasets/m-p/315837#M68935</link>
      <description>&lt;P&gt;You need a way to&amp;nbsp;retain the maximum dose when there are multiple EX records on a date.&amp;nbsp; In addition you have to retain the most recent EXDOSE in cas&amp;nbsp;you encounter a date with an AE record but no EX record:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (rename=(date=aedate) drop=prior_dose);
  merge ae (rename=(aedate=date)) 
        ex (in=inex keep=id exdate exdose rename=(exdate=date));
  by id date;

  retain prior_dose;

  if first.id then prior_dose=.;
  if inex then do;
    if first.date then prior_dose=exdose;
    else exdose=max(exdose,prior_dose);
  end;
  else exdose=prior_dose;
  if inae;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 07:28:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-values-by-comparing-dates-in-two-datasets/m-p/315837#M68935</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-12-01T07:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning values by comparing dates in two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-values-by-comparing-dates-in-two-datasets/m-p/315865#M68943</link>
      <description>&lt;PRE&gt;
You have multiple obs for the same date and same id. Keep the last one you want.

proc sort data=ex;by id exdate;run;
data new_ex;
 set ex;
 by id exdate;
 if last.exdate;
run;

then PROC SQL.

&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Dec 2016 09:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-values-by-comparing-dates-in-two-datasets/m-p/315865#M68943</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-01T09:27:54Z</dc:date>
    </item>
  </channel>
</rss>

