<?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: SAS/SQL, how to getting rolling max with rolling and changing window-length?! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975373#M378094</link>
    <description>&lt;P&gt;Why would it matter if you used PROC SQL or something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should check if you have SAS/ETS licensed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/etsug/etsug_expand_overview.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/etsug/etsug_expand_overview.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Sep 2025 13:53:48 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-09-19T13:53:48Z</dc:date>
    <item>
      <title>SAS/SQL, how to getting rolling max with rolling and changing window-length?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975360#M378088</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp(drop=i j);
do i=1 to 3;
	do j=0 to 100;
    	byvar=i;
        ind=j;
        x1=sin(j/10)+i;
        y1=cos(j/10)+i;
       	output;
  	end;
end;
run;quit;

/*proc sgplot data=temp;
	by byvar;
	series x=ind y=x1/lineattrs=(color=red thickness=2 pattern=solid);  
	series x=ind y=y1/y2axis lineattrs=(color=blue thickness=2 pattern=solid);  
run;quit;*/

proc sql;
create table temp_new as
SELECT byvar, ind, x1, y1,
       MAX(x1) OVER(ORDER BY byvar ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
       AS x1_running_max
FROM temp
group by byvar;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I need get the max from the first row to CURRENT ROW. Tried the code above. But it complains. Anyway to do it in SQL?! Surely in dataset with byvar-retain it is doable. I prefer in SAS/SQL.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Sep 2025 10:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975360#M378088</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2025-09-19T10:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL, how to getting rolling max with rolling and changing window-length?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975364#M378090</link>
      <description>&lt;P&gt;PROC SQL doesn't allow these types of 'windowing' functions, unfortunately (not sure about FEDSQL).&amp;nbsp; In a DATA step, you can do something like the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have; by id; run;

data want;
set have;
by id;
RETAIN x1_running_max y1_running_max;
if first.id then call missing(x1_running_max, y1_running_max);
x1_running_max=max(x1, x1_running_max);
y1_running_max=max(y1, y1_running_max);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Sep 2025 11:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975364#M378090</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-09-19T11:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL, how to getting rolling max with rolling and changing window-length?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975365#M378091</link>
      <description>&lt;P&gt;Unfortunately SAS SQL does not support window functions.&lt;/P&gt;
&lt;P&gt;And I can't see how to solve this in ANSI 1992 SQL, at least easily.&lt;/P&gt;
&lt;P&gt;The data step is probably your best option here.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Sep 2025 11:39:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975365#M378091</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2025-09-19T11:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL, how to getting rolling max with rolling and changing window-length?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975366#M378092</link>
      <description>just edited - forgot you were trying to do this within each level of ID.</description>
      <pubDate>Fri, 19 Sep 2025 11:46:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975366#M378092</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-09-19T11:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL, how to getting rolling max with rolling and changing window-length?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975371#M378093</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409584"&gt;@hellohere&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409584"&gt;@hellohere&lt;/a&gt;&amp;nbsp;wrote:
&lt;P&gt;I prefer in SAS/SQL.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.*, max(b.x1) as x1_running_max
from temp a, temp b
where a.byvar=b.byvar &amp;amp; b.ind&amp;lt;=a.ind
group by 1,2,3,4;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Sep 2025 12:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975371#M378093</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-09-19T12:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL, how to getting rolling max with rolling and changing window-length?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975373#M378094</link>
      <description>&lt;P&gt;Why would it matter if you used PROC SQL or something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should check if you have SAS/ETS licensed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/etsug/etsug_expand_overview.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/etsug/etsug_expand_overview.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Sep 2025 13:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975373#M378094</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-09-19T13:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL, how to getting rolling max with rolling and changing window-length?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975377#M378095</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by byvar;
retain x1_running_max;
if first.byvar
then x1_running_max = x1;
else x1_running_max = max(x1_running_max,x1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Straightforward, easy to understand, and less time- and resource-consuming than anything you might do in SQL.&lt;/P&gt;
&lt;P&gt;Maxim 14!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just for illustration, a comparison of the DATA step method with the one SQL suggestion:&lt;/P&gt;
&lt;PRE&gt; 69         data have (drop=i j);
 70         do i = 1 to 1000;
 71           do j = 0 to 100;
 72             byvar=i;
 73             ind=j;
 74             x1=sin(j/10)+i;
 75             y1=cos(j/10)+i;
 76             output;
 77           end;
 78         end;
 79         run;
 
 NOTE: The data set WORK.HAVE has 101000 observations and 4 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              1931.21k
       OS Memory           22180.00k
       Timestamp           19.09.2025 03:00:09 nachm.
       Step Count                        62  Switch Count  2
       Page Faults                       0
       Page Reclaims                     165
       Page Swaps                        0
       Voluntary Context Switches        9
       Involuntary Context Switches      2
       Block Input Operations            0
       Block Output Operations           6408
       
 
 80         
 81         data want;
 82         set have;
 83         by byvar;
 84         retain x1_running_max;
 85         if first.byvar
 86         then x1_running_max = x1;
 87         else x1_running_max = max(x1_running_max,x1);
 88         run;
 
 NOTE: There were 101000 observations read from the data set WORK.HAVE.
 NOTE: The data set WORK.WANT has 101000 observations and 5 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.01 seconds
       user cpu time       0.02 seconds
       system cpu time     0.00 seconds
       memory              3625.37k
       OS Memory           24488.00k
       Timestamp           19.09.2025 03:00:09 nachm.
       Step Count                        63  Switch Count  2
       Page Faults                       0
       Page Reclaims                     519
       Page Swaps                        0
       Voluntary Context Switches        13
       Involuntary Context Switches      1
       Block Input Operations            0
       Block Output Operations           7944
       
 
 89         
 90         proc sql;
 91         create table want as
 92         select a.*, max(b.x1) as x1_running_max
 93         from have a, have b
 94         where a.byvar=b.byvar &amp;amp; b.ind&amp;lt;=a.ind
 95         group by 1,2,3,4;
 NOTE: Table WORK.WANT created, with 101000 rows and 5 columns.
 
 96         quit;
 NOTE:  Verwendet wurde: PROZEDUR SQL - (Gesamtverarbeitungszeit):
       real time           1.50 seconds
       user cpu time       3.00 seconds
       system cpu time     0.27 seconds
       memory              459314.90k
       OS Memory           481956.00k
       Timestamp           19.09.2025 03:00:11 nachm.
&lt;/PRE&gt;
&lt;P&gt;0.01 seconds vs. 1.5 seconds. 'Nuff said.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Sep 2025 15:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975377#M378095</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-09-19T15:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL, how to getting rolling max with rolling and changing window-length?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975400#M378100</link>
      <description>&lt;P&gt;Thanks all.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dataset is just for example. I prefer SQL because DO-With-Dataset is kind of tedious in term of coding, may&lt;/P&gt;
&lt;P&gt;I say this.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Sep 2025 06:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975400#M378100</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2025-09-20T06:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL, how to getting rolling max with rolling and changing window-length?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975402#M378101</link>
      <description>&lt;P&gt;PROC SQL can not handle BIG table for your question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; already gave you the Cartesian Product Solution. Here I want to present sub-query solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp(drop=i j);
do i=1 to 3;
do j=0 to 100;
byvar=i;
ind=j;
x1=sin(j/10)+i;
y1=cos(j/10)+i;
output;
end;
end;
stop;
run;

proc sql;
create table want as
select a.*,
(select max(x1) from temp where byvar=a.byvar and ind &amp;lt;= a.ind) as x1_running_max,
(select max(y1) from temp where byvar=a.byvar and ind &amp;lt;= a.ind) as y1_running_max
 from temp as a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Sep 2025 07:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975402#M378101</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-09-20T07:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/SQL, how to getting rolling max with rolling and changing window-length?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975435#M378115</link>
      <description>&lt;P&gt;Everyone has their preferences.&amp;nbsp; SQL syntax is very good for somethings.&amp;nbsp; But in general it is extremely verbose and much more cumbersome that DATA step code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take your example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table temp_new as
SELECT byvar, ind, x1, y1,
       MAX(x1) OVER(ORDER BY byvar ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
       AS x1_running_max
FROM temp
group by byvar;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In a data step that is just:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
  set temp;
  by byvar;
  if first.byvar then x1_running_max=x1;
  else x1_running_max=max(x1_running_max,x1);
  retain x1_running_max;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So instead of having the say "create table...as...from" you just need to say "data...set...".&amp;nbsp; Instead of "group by" you just need "by".&amp;nbsp; Plus you don't have to put COMMAS between the names in the list if more than one BY variable is need.&amp;nbsp; Instead you can just use spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And SQL does not support variable lists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Sep 2025 14:35:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-SQL-how-to-getting-rolling-max-with-rolling-and-changing/m-p/975435#M378115</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-09-21T14:35:52Z</dc:date>
    </item>
  </channel>
</rss>

