New Contributor
Posts: 2

# product of a series in sas?

Hi,

Does anyone happen to know how to find a product of a series in sas?

Thanks,
OC
Posts: 2,125

## Re: product of a series in sas?

You'll need to be more specific. What kind of series? What kind of data? Do you have an example?
New Contributor
Posts: 2

## Re: product of a series in sas?

I have multiple observations of different event ranges and I would like to multiply variables in each event range conditional on the given observation [similar to using PROC MEANS and summing a variable] but instead of summing, I would like to multiply the variable.
Not applicable
Posts: 0

## Re: product of a series in sas?

An indirect approach for non-zero numbers is the log transformation. Use PROC MEANS for sum(log(|x|)) and sum(x<0), then prod(x) = (-1)^sum(x<0) * e^sum(log(|x|)).
Posts: 2,125

## Re: product of a series in sas?

The direct approach is to use the RETAIN statement, with the BY statement to designate the groupings. See

http://support.sas.com/documentation/cdl/en/lrdict/59540/HTML/default/a000214163.htm

for an example of using RETAIN. Something like

DATA rawdata;
INPUT group value;
DATALINES;
1 1
1 2
1 3
2 4
2 5
2 6
;
RUN;

DATA products;
SET rawdata;
BY group;
RETAIN Prod;
IF first.group THEN prod=1;
prod=prod*value;
IF last.group THEN OUTPUT;
run;
Discussion stats
• 4 replies
• 139 views
• 0 likes
• 3 in conversation