Chapter Contents

Previous

Next
COPYARRAY

COPYARRAY



Copies data from one array into another array

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>);

rc
indicates whether the operation was successful.
0 successful
[ne]0 not successful

Type: Numeric

source_array
is the array to copy the values from.

Type: Array

target_array
is the array to copy the values into.

Type: Array

ignoresize
indicates whether to check for array sizes to be the same.
'Y' tells SCL to check whether the source and target arrays are the same size.
'N' tells SCL to ignore array sizes. (This value is the default.)
Type: Character


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

Example 1: Copy Elements of a One-Dimensional Array

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

Example 2: Copy Elements of a Two-Dimensional Array

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;
    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

DELARRAY

MAKEARRAY

REDIM

SCL Arrays


Chapter Contents

Previous

Next

Top of Page

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