您的层次结构是市场/细分/项目,也许可以从问题中假设项目在所有市场和细分中是唯一的。
在DATA步骤中,运行总计最简单。你会想要使用 first. 步骤具有的自动变量 BY 声明。
first.
BY
data want; set have; by Market Segment Item Month; * add month to make sure incoming data is ordered timewise, if not an error will appear in the log; if first.Item then RunningDollars = 0; RunningDollars + Dollars; * The + syntax here is a `SUM` statement that causes the RunningDollars variable to be automatically retaine, meaning the value is available for the next record. run;