SAS Component Language Dictionary |
Category: | Array |
Syntax | |
Details | |
Examples | |
Example 1: Copy Elements of a One-Dimensional Array | |
Example 2: Copy Elements of a Two-Dimensional Array | |
See Also |
Syntax |
rc=COPYARRAY(source_array,target_array<,ignoresize>); |
indicates whether the operation was successful.
0 |
successful |
0 |
not successful |
Type: Numeric
is the array to copy the values from.
Type: Array
is the array to copy the values into.
Type: Array
indicates whether to check for array sizes to be the same.
'Y' |
tells SCL to ignore array sizes. |
'N' |
tells SCL to check whether the source and target arrays are the same size. (This value is the default.) |
Details |
The COPYARRAY function allows you to copy data from one array (source_array) into another array (target_array). The arrays must have the same dimensions and size and be of the same type. The source array being copied from can be a static or dynamic array, but if it is a dynamic array then its size must already have been set using MAKEARRAY or REDIM. The target array being copied into can also be a static or dynamic array. If it is dynamic and has not yet been created, then COPYARRAY will create the array to the same size of the source array. However, the low bound of a dynamic array is always 1, so the resultant target array may end up with different low or high bounds in each of its dimensions.
If you set ignoresize to 'Y', then the sizes of the arrays do not have to match. Only the types and dimensions of the arrays have to match. In this case, if the source array is bigger than the target array, then the elements in the source array will be truncated, and you will lose the data in the elements that do not coincide. If the source array is smaller than the target array, then the elements in target array that are not set will be automatically set to missing values.
If the COPYARRAY is used to create a dynamic array, the DELARRAY function should be used to delete the dynamic array.
Examples |
The example copies the elements of the one-dimensional array A into the one-dimensional array B and prints out the contents of the arrays.
DCL num a(5) b(5); do i=1 to 5; a[i] = i; end; rc = copyarray(a,b); put a=; put b=;
The result of this code would be:
a= a[1] = 1 a[2] = 2 a[3] = 3 a[4] = 4 a[5] = 5 b= b[1] = 1 b[2] = 2 b[3] = 3 b[4] = 4 b[5] = 5
The example copies the elements of the two-dimensional array A into the two-dimensional array B and prints out the contents of the arrays.
DCL num a(2,2) b(3,4); count=0; do i=1 to 2; do j=1 to 2; count+1; a[i,j] = count; end; end; rc = copyarray(a,b,'y'); put a=; put b=;
The result of this code would be:
a= a[1,1] = 1 a[1,2] = 2 a[2,1] = 3 a[2,2] = 4 b= b[1,1] = 1 b[1,2] = 2 b[1,3] = . b[1,4] = . b[2,1] = 3 b[2,2] = 4 b[2,3] = . b[2,4] = . b[3,1] = . b[3,2] = . b[3,3] = . b[3,4] = .
See Also |
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.