<?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: Find Max between 2 date for each id in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-Max-between-2-date-for-each-id/m-p/808223#M318681</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql,
create table want as
  select
    t1.id,
    t1.start,
    t1.end,
    max(t2.date) as maxdate
  from condition t1 left join have t2
  on t1.id = t2.id and t1.start le t2.date le t1.end
  group by t1.id, t1.start, t1.end
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
    <pubDate>Sun, 17 Apr 2022 08:12:08 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-04-17T08:12:08Z</dc:date>
    <item>
      <title>Find Max between 2 date for each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Max-between-2-date-for-each-id/m-p/808216#M318676</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have 2 datasets:&lt;/P&gt;
&lt;P&gt;1st data has id, date and value&lt;/P&gt;
&lt;P&gt;2nd data has id, start and end date.&lt;/P&gt;
&lt;P&gt;I want to find the Max value between start and end date for each ID&lt;/P&gt;
&lt;P&gt;I know my code below is wrong at the Point=i step but don't know how to fix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please help to fix or suggest solution?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id date value;
datalines;
1 1 5
1 2 6
1 3 8
1 4 1
1 5 9999
1 6 99
1 7 11111
2 1 5
2 2 7
2 3 90
2 4 8
2 5 18
2 6 20
;run;

data condition;
input id start end;
datalines;
2 2 4
1 3 6
2 2 6 
;run;


data w; set condition;
max=0;
set have (rename=(id=id2));
if id = id2 then do;
	do i=start to end-1;
		set have point=i;
		if start&amp;lt;=date&amp;lt;end then do;
			if max&amp;lt;value then max=value;
		end;
	end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Apr 2022 02:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Max-between-2-date-for-each-id/m-p/808216#M318676</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-04-17T02:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Find Max between 2 date for each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Max-between-2-date-for-each-id/m-p/808223#M318681</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql,
create table want as
  select
    t1.id,
    t1.start,
    t1.end,
    max(t2.date) as maxdate
  from condition t1 left join have t2
  on t1.id = t2.id and t1.start le t2.date le t1.end
  group by t1.id, t1.start, t1.end
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Apr 2022 08:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Max-between-2-date-for-each-id/m-p/808223#M318681</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-17T08:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: Find Max between 2 date for each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Max-between-2-date-for-each-id/m-p/808274#M318710</link>
      <description>This sql code work nicely.&lt;BR /&gt;I am still looking for way to fix my code.&lt;BR /&gt;Thanks,&lt;BR /&gt;HHC&lt;BR /&gt;</description>
      <pubDate>Mon, 18 Apr 2022 03:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Max-between-2-date-for-each-id/m-p/808274#M318710</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-04-18T03:36:49Z</dc:date>
    </item>
  </channel>
</rss>

