Language Reference

CREATE Statement

creates a new SAS data set

CREATE SAS-data-set <VAR operand>;
CREATE SAS-data-set FROM matrix-name
           <[COLNAME=column-name ROWNAME=row-name]>;

The inputs to the CREATE statement are as follows:

SAS-data-set
can be specified with a one-level name (for example, A) or a two-level name (for example, SASUSER.A).
operand
gives a set of existing IML variables to become data set variables.

matrix-name
names a matrix containing the data.

column-name
is a character matrix or quoted literal containing descriptive names to associate with data set variables.

row-name
is a character matrix or quoted literal containing descriptive names to associate with observations on the data set.
The CREATE statement creates a new SAS data set and makes it both the current input and output data sets. The variables in the new SAS data set are either the variables listed in the VAR clause or variables created from the columns of the FROM matrix. The FROM clause and the VAR clause should not be specified together.

You can specify a set of variables to use with the VAR clause, where operand can be specified as one of the following: The following examples demonstrate each possible way you can use the VAR clause:
  
    var {time1 time5 time9}; /* a literal giving the variables */ 
    var time;                /* a matrix containing the names  */ 
    var('time1':'time9');    /* an expression                  */ 
    var _all_;               /* a keyword                      */
 
You can specify a COLNAME= and a ROWNAME= matrix in the FROM clause. The COLNAME= matrix gives names to variables in the SAS data set being created. The COLNAME= operand specifies the name of a character matrix. The first ncol values from this matrix provide the variable names in the data set being created, where ncol is the number of columns in the FROM matrix. The CREATE statement uses the first ncol elements of the COLNAME= matrix in row-major order.

The ROWNAME= operand adds a variable to the data set to contain row titles. The operand must be a character matrix that exists and has values. The length of the data set variable added is the length of a matrix element of the operand. The same ROWNAME= matrix should be used in any subsequent APPEND statements for this data set.

The variable types and lengths are the current attributes of the matrices specified in the VAR clause or the matrix in the FROM clause. The default type is numeric when the name is undefined and unvalued. The default, when no variables are specified, is all active variables. To add observations to your data set, you must use the APPEND statement.

For example, the following statements create a new SAS data set CLASS having variables NAME, SEX, AGE, HEIGHT, and WEIGHT. The data come from IML matrices with the same names. You must initialize the character variables (NAME and SEX) and set the length prior to invoking the CREATE statement. NAME and SEX are character variables of lengths 12 and 1, respectively. AGE, HEIGHT, and WEIGHT are, by default, numeric.

  
    name="123456789012"; 
    sex="M"; 
    create class var {name sex age height weight}; 
    append;
 
In the next example, you use the FROM clause with the COLNAME= operand to create a SAS data set named MYDATA. The new data set has variables named with the COLNAME= operand. The data are in the FROM matrix x, and there are two observations because x has two rows of data. The COLNAME= operand gives descriptive names to the data set variables. Here is the code:

  
    x={1 2 3, 4 5 6}; 
    varnames='x1':'x3'; 
       /* creates data set MYDATA with variables X1, X2, X3  */ 
    create mydata from x [colname=varnames]; 
    append from x;
 

Previous Page | Next Page | Top of Page