Language Reference

APPEND Statement

adds observations to the end of a SAS data set

APPEND < VAR operand > ;
APPEND < FROM from-name < [ROWNAME=row-name] > > ;

In the preceding statements,
operand
can be specified as one of the following:
  • a literal containing variable names
  • a character matrix containing variable names
  • an expression in parentheses yielding variable names
  • one of the keywords described in the following list:
    _ALL_
    for all variables

    _CHAR_
    for all character variables

    _NUM_
    for all numeric variables


from-name
is the name of a matrix containing data to append.

row-name
is a character matrix or quoted literal containing descriptive row names.

Use the APPEND statement to add data to the end of the current output data set. The appended observations are from either the variables specified 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.

The following statements show 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                      */
 
If the VAR clause includes a matrix with more than one row and column, the APPEND statement adds one observation for each element in the matrix with the greatest number of elements. Elements are appended in row-major order. Variables in the VAR clause with fewer than the maximum number of elements contribute missing values to observations after all of their elements have been used.

The default variables for the APPEND statement are all matrices that match variables in the current data set with respect to name and type.

The ROWNAME= operand to the FROM clause specifies the name of a character matrix to contain row titles. The first nrow values of this matrix become values of a variable with the same name in the output data set; nrow is the number of rows in the FROM matrix. The procedure uses the first nrow elements in row-major order.

The following examples demonstrate the use of the APPEND statement. The first example shows the use of the FROM clause when creating a new data set. For more information, see the section "CREATE Statement". Here is the code:

  
    x={1 2 3, 4 5 6}; 
    create mydata from x[colname={x1 x2 x3}]; 
    append from x; 
    show contents; 
       /* shows 3 variables (x1 x2 x3) and 2 observations */
 
The next example shows the use of the VAR clause for selecting variables from which to append data. Here is the code:
  
    names={'Jimmy' 'Sue' 'Ted'}; 
    sex={m f m}; 
    create folks var{names sex}; 
    append; 
    show contents; 
    /* shows 2 variables (names,sex) and 3 observations in FOLKS */
 
You could achieve the same result with the following statements:
  
    dsvar={names sex}; 
    create folks var dsvar; 
    append;
 

Previous Page | Next Page | Top of Page