Mostly, I avoid the use of the LAG function in PROC REPORT, because PROC REPORT is building one report row at a time, it really doesn't have visibility of the previous report rows when it's writing a new report row -- unless you save out the information into temporary variables. And, while the Data step program has a PDV (program data vector) from which it can retrieve and store lagged values, PROC REPORT does not have a PDV -- it only has some buffer areas where the summarized report information is held while the report rows are being written.
It sounds like you have a fairly complicated PROC REPORT step. You may wish to work with Tech Support on this question, as they can look at your data and at your entire program and help you come up with the correct approach.
Here's an example that I had. It shows two things: there are a BUNCH of temporary variables and there's one COMPUTED variable (SILLYVAR). The difference between the two types of variables is outlined in a documentation topic entitled, "".
This is a very simple example of how certain values were saved into temporary variables in a compute block and then used -- in this case, at the end of the report.
ods listing close;
ods html file='c:\temp\use_temp_var.html' style=sasweb;
proc report data=sashelp.class nowd
title 'Example: Using Temporary Variables';
title2 'HT12, HT14, HOLD12, HOLD14, AV12, AV14, HOLDALL and HTALL are the temp variables';
title3 'SillyVar is a COMPUTED variable';
column age n height weight sillyvar;
define age / group;
define n / 'Count';
define height / mean 'Avg Height';
define weight / mean 'Avg Weight';
define sillyvar / computed 'Silly Var';
sillyvar = weight.mean - height.mean;
if age = 12 then do; hold12 = n; ht12 = height.mean; end;
else if age = 14 then do; hold14 = n; ht14 = height.mean; end;
if _break_ = '_RBREAK_' then do; holdall = n; htall = height.mean; end;
rbreak after / summarize;
av12 = hold12 / holdall;
av14 = hold14 / holdall;
line 'Average Height for 12 year olds: ' ht12 4.1 ;
line 'This group is ' av12 percent8.2 'of all ages which represents' hold12 2.0 ' divided by ' holdall 2.0;
line ' ';
line 'Average Height for 14 year olds: ' ht14 4.1 ;
line 'This group is ' av14 percent8.2 'of all ages which represents' hold14 2.0 ' divided by ' holdall 2.0;
line ' ';
line 'The overall Average Height is: ' htall 4.1;
ods html close;