SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Reading and Concatenating SAS Data Sets
Lesson Summary

This page contains


I. Text Summary

To go to the page where a task, programming feature, or concept was presented, select a link.


Setting Up
Before you can create a new data set, you must assign a libref to the SAS data library that is storing the data set to be used.

Reading a Single Data Set
After you have referenced the library where your data set is stored, you can write a DATA step to name the SAS data set to be created. You then specify the data set to be read in the SET statement.

Selecting Observations
To select only those observations that meet a specified condition, you can use a subsetting IF statement in any DATA step. If the variable you select is a character variable, the value must be enclosed in quotation marks and be the same case as in the data set.

Selecting Variables
You can select the variables you want to drop or keep using the DROP= and KEEP= data set options in parentheses after a SAS data set name. You can use DROP= if more variables are dropped than kept.

Merging vs. Concatenating
There are two basic ways to combine data sets: concatenating and merging. In concatenating, data sets in the SET statement are read sequentially, in the order in which they are listed, until all observations have been processed. The new data set contains all the variables from all the input data sets and the total number of records from all input data sets. Most merges are combined with a BY statement to produce a match-merge of two or more data sets. When a BY statement is used, observations are match-merged according to the values of the BY variable(s). This lesson discusses concatenating.

Concatenating SAS Data Sets
You may want to append one data set to another. In this process known as concatenating, data sets in the SET statement are read sequentially in the order in which they are listed.  The process continues until all observations have been read. The new data set contains the total number of records from all input data sets.


II. Syntax

To go to the page where a statement or option was presented, select a link.

LIBNAME libref  'SAS-data-library';
DATA <SAS-data-set> (KEEP= variable-1 < . . . variable-n>);
       SET SAS-data-set (DROP= variable-1 < . . . variable-n>);
       IF expression;
RUN;


III. Sample Program
     libname clinic 'c:\stress\labdata';
     data clinic.newdata(keep=id sex kgwgt);
        set clinic.admit(drop=name date);
        if actlevel='LOW';
        kgwgt=height/2.2;
     run;


IV. Points to Remember
  • When concatenating, you can specify the DROP= or KEEP= options in either the DATA statement or the SET statement, depending on whether or not you want to process values of the variables in that DATA step.

  • You can concatenate any number of SAS data sets.



back||next

 

Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement