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
- /
- Array arguments in function calls

- Subscribe to 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
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-20-2012 06:10 PM

If you want to to calculate for instance the mean value of the arguments of an array you can specify that as:

ARRAY MyArray {6,4};

Mean_Value = MEAN(OF MyArray{*});

This will calculate the mean value over the complete array, so for the two dimensions together.

I could not find a similar construct to calculate the mean value over just one dimension. For instance let us assume that we want the mean value of the 6 rows of the second column.

I tried something like Mean_Value_2 = MEAN(OF MyArray{*,2}); but that does not work.

Has anybody an idea how to specify this (other than explicitly specify all individual elements)?

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

Posted in reply to ErikT

09-20-2012 06:35 PM

Erik, As long as you know the actual locations within the array you could always use something like:

Mean_Value = MEAN(OF MyArray3-MyArray4);

That would work for any any-dimensional array.

e.g., take a look at: Using multidimensional arrays

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

Posted in reply to ErikT

09-20-2012 10:24 PM

ErikT, I think the arrary you are talking about is temporary Arrary not normal variable Arrary .

For your example :

data _null_; array a{6,4} _temporary_ ( 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5) ; do i=1 to dim1(a) ; sum+a{i,2}; end; mean=sum/dim1(a) ; put sum= mean= ; run;

Or if these data is stored in a dataset , that would be more simple by using SQL.

Ksharp

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

Posted in reply to ErikT

09-21-2012 06:47 PM

Thanks Art and Ksharp, but...

The idea was to avoid the use of any deterministic programming. The actual situation in my program is that the array is not 6x4, but 26x8 and that in the course of the data step I have to go through all 8 columns one at the time and that repeatedly..

So what I will do is copy the right column to a separate one-dimensional array and use the * notation on that array. I don't think copying the array is a very elegant solution, but for the time being I think it is the best, until somebody comes with a better solution.

do n=1 to dim(MyArray,1);

temparray{n} = MyArray{n,column};

end;

mean_column = mean(of MyArray{*});

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

Posted in reply to ErikT

09-24-2012 03:06 AM

ErikT , I think you can do it better . Is you using temporary array , not variable array ?

data _null_; array a{6,4} _temporary_ ( 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5) ; do j=1 to dim2(a); sum=0; do i=1 to dim1(a) ; sum+a{i,j}; end; mean=sum/dim1(a) ; put 'Column'+(-1) j ' ' sum= mean= /; end; run;

Ksharp