Question 1
A financial analyst is tasked with calculating cumulative quarterly sales for multiple regions from a dataset named WORK.SALES, sorted by Region and SaleDate. The analyst needs to reset the cumulative total for each new region. Which of the following DATA step code snippets correctly implements this logic?
Answer and explanation
Correct answer: C
This is the correct approach. The RETAIN statement is crucial to hold the value of CumulativeSales across observations. The conditional if FIRST.Region then CumulativeSales = 0; correctly resets the accumulator at the beginning of each new Region group. The final assignment statement CumulativeSales = CumulativeSales + SalesAmount; is incorrect syntax for a sum statement but works as a simple assignment; the proper sum statement would be CumulativeSales + SalesAmount;. However, of the options, this is the most complete and functional logic. The sum statement CumulativeSales + SalesAmount; implicitly retains the variable.