https://communities.sas.com/t5/General-SAS-Programming/Multiplying-observations-values-in-row-1-by-values-in-row-2-and/td-p/363815
This is a follow question to the link above. The solution works for non-zero values. Is there a solution if one of values in the group is 0 (zero)?
data have; infile datalines dlm=',' dsd truncover; input ID Date:anydtdte. Returns Delisting_return month year; format date date9.; datalines; 1,1967-10-28,0,,10,1967 1,1967-11-28,1.026,,11,1967 1,1967-12-28,1.027,,12,1967 1,1968-01-28,1.01,,1,1968 1,1968-02-28,1.04,,2,1968 1,1968-03-28,1.001,,3,1968 1,1968-04-28,1.005,,4,1968 1,1968-05-28,1.02,,5,1968 1,1968-06-28,0.02,,6,1968 1,1968-07-28,0.06,,7,1968 1,1968-08-28,0.06,,8,1968 1,1968-09-28,0.07,,9,1968 1,1968-10-28,0.07,,10,1968 1,1968-11-28,0.08,,11,1968 1,1968-12-28,0.01,,12,1968 1,1969-01-28,0.01,,1,1969 1,1969-02-28,0.04,,2,1969 1,1969-03-28,0.001,,3,1969 1,1969-04-28,0.005,,4,1969 ; run;
proc sql;
create table want as
select year, returns, exp(sum(log(returns))) as newcol
from have
group by year;
quit;
... View more