turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- SAS function PROD not working

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-04-2017 05:17 AM

Hi,

Here's a real easy problem. It could be due to my PC SAS version 9.4 running Windows 7.

I am trying to multiply all the elements of a vector using SAS function PROD, but it is giving me an error "ERROR 68-185: The function PROD is unknown, or cannot be accessed." The vector may include missing values. The idea is very similar to SAS function SUM, which ignores missing values and sums all the values of the vector.

For example:

```
data _null_;
a = prod(2, 1, ., 3);
put "a equals " a;
run;
```

But then I get the error. If instead of "prod" I write "sum", there is no error.

Is there something wrong with my base SAS? Do other people have the same problem? What am I doing wrong?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to iank131

02-04-2017 06:18 AM

I expect you should be using PROD() in SAS/IML

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Peter_C

02-04-2017 06:31 AM

SUM() is also SAS/IML but it works in base SAS. I am wondering why PROD() does not work in base SAS, or if is there an equivalent such function? Thanks.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to iank131

02-04-2017 06:45 AM

PROD() was introduced with SAS/IML, much later than the SUM() function that has been in Base SAS as long as I can remember (SAS 6.09).

It seems nobody ever had a real need for such a function in Base.

You might put it up as a ballot idea.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to iank131

02-04-2017 06:44 AM

So in a product context, you want your missing values to be treated like a 1 right?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to draycut

02-04-2017 10:33 AM

Yes. Or just ignore missing values.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to iank131

02-05-2017 08:05 AM

There is not a PROD() function in BASE SAS. But if your numbers are positive then you might be able to use GEOMEAN() function instead. Example:

```
data have ;
input a1-a4 ;
cards;
2 1 . 3
1 1 1 1
10 10 10 10
;
data want ;
set have;
array x a1-a4 ;
prod1 = 1;
do i=1 to dim(x);
prod1=prod1*coalesce(x(i),1);
end;
prod2=geomean(of x(*))**n(of x(*));
put (_all_) (=);
run;
```