Chapter Contents

Previous

Next
SAS Component Language: Reference

Returning Arrays From Methods

Arrays can also be assigned values from a method that returns an array. The array to which values are being assigned must have the same type, dimensions, and size as the array returned from the method. Otherwise, an error condition will occur.

Suppose you define the getArrayValues method as follows:

getArrayValues:method return=num(*);
declare num a[3] = (1 3 5);
return a;
endmethod;
To assign the values that are returned by getArrayValues to an array, you could use the following code:
declare num b[3];
b = object.getArrayValues();
put b;
The output for this example is
b[1] = 1
b[2] = 3
b[3] = 5

Dynamic arrays (that have not yet been created by other means) can be created when an array is returned from a method call. If your program returns values into a dynamic array that has been declared but not yet created, SCL will first create the new dynamic array, then copy the returned values into the new array. For example, the following code creates dynamic array B with the same size as the returned array and copies the values of the returned array into B.

declare num b[*];
b = getArrayValues();
put b;
The output of these statements is
b[1] = 1
b[2] = 3
b[3] = 5


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.