You can't use RETAIN with the variables coming in from the dataset on the set
statement; or more accurately, you can, but it won't work - variables are RETAIN
ed automatically on variables from set statements. They are also, however, overwritten by the next iteration of the data step when the set
occurs.
You can either use a temporary array to store the retained values and copy it back over when last.date
(temporary arrays are also retained automatically, FYI), or you can use a different technique entirely - hash tables, SQL, whatever you're most familiar with.
For example,
proc sql;
create table want as
select cust, date, sum(var1) as var1, sum(var2) as var2, ...
from have
group by cust,date;
quit;
You would want to construct the sum(var1) as var1
in a macro variable, something like
%macro sumvar(var=)
sum(&var.) as &var.
%mend sumvar;
proc sql;
select cats('%sumvar(var=',name,')')
into :sumlist separated by ','
from dictionary.columns
where libname='WORK' and memname='HAVE' and not (name in ('CUST','DATE'))
;
quit;
and then use that &sumlist. in the sql above.
select cust, date, &sumlist.
This is probably the easiest to code; it's probably not as efficient as other options if you have really large data.