<?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 Find rolling max from today up to start day in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-rolling-max-from-today-up-to-start-day/m-p/878084#M346915</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;My data has ID, date, Value. For each Id, at a given date, I want to find the Max value up to that date.&lt;/P&gt;
&lt;P&gt;My code below works but I wonder if there is any shorter/faster way, such as using proc expand.&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 2
1 2 15
1 3 6
1 4 17
1 5 8
1 6 9
2 1 60
2 2 50
2 3 600
;run;
proc sort data=have; by id descending date; run;

data want;
set have nobs=nobs;
drop i j _: exit;
i+1;
max_value=0;
exit=0;
do j=i to nobs until (exit=1);
	set have (keep=id date value rename=(id=_id date = _date value=_value)) point=j;
	if id^=_id then do;exit=1;leave; end;
	if max_value&amp;lt;_value then max_value=_value;

end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 29 May 2023 18:40:36 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2023-05-29T18:40:36Z</dc:date>
    <item>
      <title>Find rolling max from today up to start day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-rolling-max-from-today-up-to-start-day/m-p/878084#M346915</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;My data has ID, date, Value. For each Id, at a given date, I want to find the Max value up to that date.&lt;/P&gt;
&lt;P&gt;My code below works but I wonder if there is any shorter/faster way, such as using proc expand.&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 2
1 2 15
1 3 6
1 4 17
1 5 8
1 6 9
2 1 60
2 2 50
2 3 600
;run;
proc sort data=have; by id descending date; run;

data want;
set have nobs=nobs;
drop i j _: exit;
i+1;
max_value=0;
exit=0;
do j=i to nobs until (exit=1);
	set have (keep=id date value rename=(id=_id date = _date value=_value)) point=j;
	if id^=_id then do;exit=1;leave; end;
	if max_value&amp;lt;_value then max_value=_value;

end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 18:40:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-rolling-max-from-today-up-to-start-day/m-p/878084#M346915</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2023-05-29T18:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: Find rolling max from today up to start day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-rolling-max-from-today-up-to-start-day/m-p/878086#M346917</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My data has ID, date, Value. For each Id, at a given date, I want to find the Max value up to that date.&lt;/P&gt;
&lt;P&gt;My code below works but I wonder if there is any shorter/faster way, such as using proc expand.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What an odd question. The first thing you should do is look at the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/etsug/etsug_expand_toc.htm" target="_self"&gt;documentation for PROC EXPAND&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, this much simpler DATA step will work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by id;
    retain maxvalue;
    if first.id then maxvalue=value;
    else if value&amp;gt;maxvalue then maxvalue=value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 18:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-rolling-max-from-today-up-to-start-day/m-p/878086#M346917</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-29T18:48:48Z</dc:date>
    </item>
  </channel>
</rss>

