Skip to content

Instantly share code, notes, and snippets.

@statgeek
Last active January 6, 2018 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statgeek/27e23c015eae7953eff2 to your computer and use it in GitHub Desktop.
Save statgeek/27e23c015eae7953eff2 to your computer and use it in GitHub Desktop.
SAS - moving min/max using arrays
/*
How to calculate a moving min/max with a window of 4.
Resets by group ID
https://communities.sas.com/message/244232
Courtesy of PGStats
*/
data want;
array p{0:3} _temporary_;
set have; by object;
if first.object then call missing(of p{*});
p{mod(_n_,4)} = price;
lowest = min(of p{*});
highest = max(of p{*});
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment