7月 172019
 

In the SAS/IML language, a matrix contains data of one type: numeric or character. If you want to create a SAS data set that contains mixed-type data (numeric and character), SAS/IML 15.1 provides support to write multiple matrices to a data set by using a single statement. Specifically, the CREATE FROM and APPEND FROM statements now support writing multiple matrices of any types. SAS/IML 15.1 was released as part of SAS 9.4m6.

Write mixed-type data from SAS/IML objects

With the new enhancements to the CREATE FROM and APPEND FROM statements, you now have four ways to write mixed type data to a SAS data set:

Write multiple matrices to a data set

In SAS/IML 15.1, you can specify multiple matrices on the CREATE FROM statement. The matrices can be any type. In the following example, X matrix is a numeric matrix and C is a character matrix:

/* read numeric and character vars in one call */
proc iml;
NumerVarNames = {'N' 'N2' 'N3'};
X = { 1  2  3,
      2  4  6,
      3  6  9,
      4  8 12};
charVarNames = {'Animal' 'Flower'};
C = {'Rat'   'Iris', 
     'Pig'   'Rose',
     'Goat'  'Daisy', 
     'Duck'  'Lily'};
 
/* SAS/IML 15.1: write multiple matrices of any type to a SAS data sets */
AllNames = NumerVarNames || CharVarNames;
create MyData from X C [colname=AllNames];  /* specify multiple matrices */
append from X C;                            /* repeat matrix names */
close;
QUIT;
 
proc print data=MyData noobs;
run;

Although the new enhancements to the CREATE FROM and APPEND FROM statements enable you to write mixed-type data to a SAS data set, you can also write multiple matrices regardless of the types. For example, you can use the same technique to write multiple numeric matrices.

Notice that if you want to specify the names of the data set variables, you use a single COLNAME= option at the end of the CREATE FROM statement.

The post Write numeric and character matrices to a data set from SAS/IML appeared first on The DO Loop.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)