SAS maximum value in preceding rows

I need to calculate max (Measure) in the last 3 months for each ID and month, without using PROC SQL.I was wondering I could do this using the RETAIN statement, however I have no idea how to implement the condition of comparing the value of Measure in the current row and the preceding two.

I will also need to prepare the above for more than 3 months so any solution that do not require a separate step for each additional month would be absolutely appreciated!

Here is the data I have:

data have; input month ID $ measure; cards; 201501 A 0 201502 A 30 201503 A 60 201504 A 90 201505 A 0 201506 A 0 201501 B 0 201502 B 30 201503 B 0 201504 B 30 201505 B 60 ; 

Here the one I need:

data want; input month ID $ measure max_measure_3m; cards; 201501 A 0 0 201502 A 30 30 201503 A 60 60   201504 A 90 90 201505 A 0 90 201506 A 0 90 201501 B 0 0 201502 B 30 30 201503 B 0 30 201504 B 30 30 201505 B 60 60 ; 

SAS maximum value in preceding rows

Replay

Category: sas Time: 2016-07-28 Views: 0
Tags: sas max rows retain

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 3.919 (s). 13 q(s)