Help using Base SAS procedures

product of a series in sas?

Reply

product of a series in sas?

Hi,

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

Thanks,
OC
Trusted Advisor
Posts: 2,116

Re: product of a series in sas?

Posted in reply to question_on_how_to_find_a_product_of_a_
You'll need to be more specific. What kind of series? What kind of data? Do you have an example?

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.
N/A
Posts: 0

Re: product of a series in sas?

Posted in reply to question_on_how_to_find_a_product_of_a_
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|)).
Trusted Advisor
Posts: 2,116

Re: product of a series in sas?

Posted in reply to question_on_how_to_find_a_product_of_a_
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;
Ask a Question
Discussion stats
  • 4 replies
  • 128 views
  • 0 likes
  • 3 in conversation