This construct creates cumulative sums, where on every record SALES is added to the value of BOOKSALES from the previous record.
booksales + sales;
It keeps adding sales into booksales on every record. But you don't want that, you want to set the booksales back to zero for each date.
But since you don't have a variable named SALES, but you do have a variable names BOOKSALES, I don't think the code as written would work. I think you want
sales+booksales;
Then last.date outputs the final cumulative sales to the data set.
Lastly, you are struggling with coding that is much simpler in PROC SUMMARY. Since SAS has done the hard work of figuring out how to compute sales across many variables, and then created PROC SUMMARY which lets you figure out the total sales in a DATE (or any other variable you want like COUNTRY or STATE or any other variable) with much less programming and much less logic to trip you up, I suggest you learn and use PROC SUMMARY for this task. Note that if you had 10 variables instead of these 4, you just add the variables into the VAR statement, you don't need to set each one to zero and then do the summation on each variable.
proc summary data=datetypesort nway;
class date;
var booksales cardsales persales totalsales;
output out=daysales sum=;
run;
... View more