Previous Page | Next Page

The FCMP Procedure

Reading Arrays and Writing Arrays to a Data Set


Overview

PROC FCMP provides the READ_ARRAY function to read arrays, and the WRITE_ARRAY function to write arrays to a data set. This functionality enables PROC FCMP array data to be processed by SAS programs, macros, and procedures.


The READ_ARRAY Function


Syntax of the READ_ARRAY Function

The READ_ARRAY function reads data from a SAS data set into a PROC FCMP array variable.

The following two forms of the READ_ARRAY function are available:

rc = READ_ARRAY (data_set_name, array_variable);
rc = READ_ARRAY (data_set_name, array_variable <, 'col_name_1', 'col_name_2', ...>);

where

rc

is 0 if the function is able to successfully read the data set.

data_set_name

specifies the name of the data set from which the array data will be read. data_set_name must be a character literal or variable that contains the member name (libname.memname) of the data set to be read from.

array_variable

specifies the PROC FCMP array variable into which the data is read. array_variable must be a local temporary array variable because the function might need to grow or shrink its size to accommodate the size of the data set.

col_name

specifies optional names for the specific columns of the data set that will be read.

If specified, col_name must be a literal string enclosed in quotation marks. col_name cannot be a PROC FCMP variable. If column names are not specified, PROC FCMP reads all of the columns in the data set.


Details

When SAS translates between an array and a data set, the array will be indexed as [row,column].

Arrays that are declared in functions and CALL routines can be resized, as well as arrays that are declared with the /NOSYMBOLS option. No other arrays can be resized.

The READ_ARRAY function attempts to dynamically resize the array to match the dimensions of the input data set. This means that the array must be dynamic. That is, the array must be declared either in a function or CALL routine or declared with the /NOSYMBOLS option.


Example of the READ_ARRAY Function

This example creates and reads a SAS data set into an FCMP array variable.

data account;
   input acct price cost;
   datalines;
1 2 3
4 5 6
;
run;

proc fcmp;
   array x[2,3] / nosymbols;
   rc = read_array('account', x);
   put x=;
run;

proc fcmp;
   array x[2,2] / nosymbols;
   rc = read_array('account', x, 'price', 'acct');
   put x=;
run;

Output from the READ_ARRAY Function

                                 The SAS System                                1

                               The FCMP Procedure

x[1, 1]=1 x[1, 2]=2 x[1, 3]=3 x[2, 1]=4 x[2, 2]=5 x[2, 3]=6
                                 The SAS System                                2

                               The FCMP Procedure

x[1, 1]=2 x[1, 2]=1 x[2, 1]=5 x[2, 2]=4

The WRITE_ARRAY Function


Syntax of the WRITE_ARRAY Function

The WRITE_ARRAY function writes data from a PROC FCMP array variable to a data set that can then be used by SAS programs, macros, and procedures. When SAS translates between an array and a data set, the array will be indexed as [row, column].

The following two forms of the WRITE_ARRAY function are available:

rc = WRITE_ARRAY (data_set_name, array_variable);
rc = WRITE_ARRAY(data_set_name, array_variable <, 'col_name_1', 'col_name_2', ...>);

where

rc

is 0 if the function is able to successfully write the data set.

data_set_name

specifies the name of the data set to which the array data will be written. data_set_name must be a character literal or variable that contains the member name (libname.memname) of the data set to be created.

array_variable

specifies the PROC FCMP array or matrix variable whose contents will be written to data_set_name.

col_name

specifies optional names for the columns of the data set that will be created.

If specified, col_name must be a literal string enclosed in quotation marks. col_name cannot be a PROC FCMP variable. If column names are not specified, the column name will be the array name with a numeric suffix.


Example 1: Using the WRITE_ARRAY Function with a PROC FCMP Array Variable

This example uses the ARRAY statement and the WRITE_ARRAY function with PROC FCMP to write output to a data set.

options nodate pageno=1 ls=80 ps=64;

proc fcmp;
   array x[4,5] (11 12 13 14 15 21 22 23 24 25 31 32 33 34 35 41 42 43 44 45);
   rc = write_array('work.numbers', x);
run;

proc print data = work.numbers;
run;

Output from Using the WRITE_ARRAY Function

                         The SAS System                                       1
                    Obs    x1    x2    x3    x4    x5

                        1     11    12    13    14    15
                        2     21    22    23    24    25
                        3     31    32    33    34    35
                        4     41    42    43    44    45

Example 2: Using the WRITE_ARRAY Function to Specify Column Names

This example uses the optional colN variable to write column names to the data set.

options pageno=1 nodate ps=64 ls=80;

proc fcmp;
   array x[2,3] (1 2 3 4 5 6);
   rc = write_array('numbers2', x, 'col1', 'col2', 'col3');
run;

proc print data = numbers2;
run;

Output from Using the WRITE_ARRAY Function to Specify Column Names

                             The SAS System                                1

                          Obs    col1    col2    col3

                           1       1       2       3
                           2       4       5       6

Previous Page | Next Page | Top of Page