<?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: How to assign values by comparing the dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-values-by-comparing-the-dates/m-p/283655#M57797</link>
    <description>&lt;P&gt;This code works, but I need the last dose and &amp;nbsp;exdate less than aedate because that is the last dose taken before ae. Your code has ABS function which rounds to positive values and the exdate greater aedate also considered. PLease help&lt;/P&gt;</description>
    <pubDate>Tue, 12 Jul 2016 01:54:45 GMT</pubDate>
    <dc:creator>knveraraju91</dc:creator>
    <dc:date>2016-07-12T01:54:45Z</dc:date>
    <item>
      <title>How to assign values by comparing the dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-values-by-comparing-the-dates/m-p/283631#M57783</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;&lt;P&gt;I have two datasets. One EX and other AE. I need create a variable called LASTDOSE in my AE dataset by comparing AEdate with exdate. Please help.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;EX&lt;/P&gt;&lt;P&gt;Subid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;exdate &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;exdose&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07FEB2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 17FEB2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;27FEB2016&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;20&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07JAN2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;17JAN2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 17JAN2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 40&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;AE&lt;/P&gt;&lt;P&gt;Subid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AEDATE&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;18FEB2016&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11JAN2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output needed.&lt;/P&gt;&lt;P&gt;Subid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Lastdose&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 18FEB2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11JAN2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For SUBID=1 10 is the last dose taken before AEdate&amp;nbsp;&lt;BR /&gt;For SUBID=2 20 is the last dose taken before AEdate&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 21:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-values-by-comparing-the-dates/m-p/283631#M57783</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-07-11T21:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign values by comparing the dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-values-by-comparing-the-dates/m-p/283637#M57788</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select a.*, exdose as Lastdose from ae a &lt;BR /&gt;inner join ex b&lt;BR /&gt;on a.subid=b.subid&lt;BR /&gt;group by a.subid&lt;BR /&gt;having abs(exdate-aedate)=min(abs(exdate-aedate));&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 22:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-values-by-comparing-the-dates/m-p/283637#M57788</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-07-11T22:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign values by comparing the dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-values-by-comparing-the-dates/m-p/283639#M57790</link>
      <description>&lt;P&gt;Proc SQL is very useful for joining on conditions. The following code should do what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
   create table want as 
   select ae.subid, ae.aedate,ex.exdose as lastdose
   from ae left join 
        (select subid, exdose
         from ex 
         group by subid
         having exdate=max(exdate))
   ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will get a warning about "remerging statistics back with original data" because of the Having clause.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is no dose associated with the SUBID then the Lastdose variable will be missing.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 22:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-values-by-comparing-the-dates/m-p/283639#M57790</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-11T22:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign values by comparing the dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-values-by-comparing-the-dates/m-p/283648#M57795</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EX;
input Subid        exdate   : date9.         exdose;
format exdate    date9.;
cards;
1              07FEB2016          5
1             17FEB2016         10
1              27FEB2016        20
2             07JAN2016         20
2            17JAN2016          30
2           17JAN2016           40
;
run;

data AE;
input Subid                AEDATE : date9.;
format   AEDATE date9.;
cards;
1                    18FEB2016
2                    11JAN2016
;
run;
proc sql;
select a.*,b.exdose
 from AE as a left join EX as b 
  on a.Subid=b.Subid and a.AEDATE-b.exdate &amp;gt;0
    group by a.Subid,a.AEDATE 
     having a.AEDATE-b.exdate=min(a.AEDATE-b.exdate);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Jul 2016 01:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-values-by-comparing-the-dates/m-p/283648#M57795</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-12T01:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign values by comparing the dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-values-by-comparing-the-dates/m-p/283655#M57797</link>
      <description>&lt;P&gt;This code works, but I need the last dose and &amp;nbsp;exdate less than aedate because that is the last dose taken before ae. Your code has ABS function which rounds to positive values and the exdate greater aedate also considered. PLease help&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 01:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-values-by-comparing-the-dates/m-p/283655#M57797</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-07-12T01:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign values by comparing the dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-values-by-comparing-the-dates/m-p/283662#M57803</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've modified the code. Please see below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select a.*, exdose as Lastdose from ae a &lt;BR /&gt;inner join ex b&lt;BR /&gt;on a.subid=b.subid&lt;BR /&gt;and exdate&amp;lt;aedate &amp;nbsp;/* Restricting exdate before acdate */&lt;BR /&gt;group by a.subid&lt;BR /&gt;having aedate-exdate=min(aedate-exdate);&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 03:23:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-values-by-comparing-the-dates/m-p/283662#M57803</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-07-12T03:23:04Z</dc:date>
    </item>
  </channel>
</rss>

