Thank so much Jagadish and Hai.Kuo! Sorry that i didn't explain the question clearly. For the same upc and week, the last_qtr_sum calculation is conditioned by last_qtr_start last_qtr_end, i.e., last_qtr_sum is the sum of units of the same upc but weeks have to be between last_qtr_start and last_qtr_end. i modified my example by adding 3 rows at the bottom to show the difference. btw, your correction of the output is correct,Jagadish, thank you! data one; input upc week units last_qtr_start last_qtr_end; datalines; 10001 1150 10 1127 1149 10001 1151 20 1128 1150 10001 1154 15 1141 1153 10001 1156 12 1143 1155 10002 1300 20 1287 1299 10002 1301 25 1288 1300 10002 1305 20 1292 1304 10002 1330 20 1317 1329 10002 1340 25 1327 1339 10002 1350 20 1337 1349 ; run; And the output should look like: data two; input upc week units last_qtr_start last_qtr_end last_qtr_sum; datalines; 10001 1150 10 1127 1149 0 10001 1151 20 1128 1150 10 10001 1154 15 1141 1153 30 10001 1156 12 1143 1155 45 10002 1300 20 1287 1299 0 10002 1301 25 1288 1300 20 10002 1305 20 1292 1304 45 10002 1330 20 1317 1329 0 10002 1340 25 1327 1339 20 10002 1350 20 1337 1349 25 ; run;
... View more