2.6 - Reading Data in From Other SAS Data Sets

In terms of telling SAS where your input data reside, we've investigated how to read instream data into a SAS data set. We've also investigated how to read data contained in an external raw data file into a SAS data set. Now, we'll investigate how to read data already contained in one SAS data set into another SAS data set.

Example 2.7 Section

The following SAS program creates a temporary SAS data set called work.temp, which is identical to the permanent SAS data set called stat480.temp2:

LIBNAME stat480 'C:\stat480\data';
    DATA temp;
      set stat480.temp2;
    PROC PRINT data=temp;
      title 'Output dataset: TEMP';

In this case:

  • because a one-level name is used, the DATA statement tells SAS to create a temporary dataset called temp.
  • the SET statement tells SAS to assign the data in the existing permanent SAS data set stat480.temp2 — observation by observation — to the temporary temp data set appearing in the DATA statement. Because the variables in the existing data set have already been named, no input statement is necessary. That is, the SET statement indicates that the data being read are already in the structure of a SAS data set, and therefore merely gives the name of the data set.

Note that before this program will work, you will have already had to create the permanent SAS data set stat480.temp2 in Example 2.2 of this lesson. Launch the SAS program. If stat480.temp2 is not stored in a directory called C:\stat480\data, you will need to edit the LIBNAME statement so it reflects the location that stat480.temp2 is stored on your computer. After convincing yourself that you've made any necessary changes, run  the SAS program and review the output. Note that the structure and contents of the new temporary data set temp are identical to the permanent SAS data set stat480.temp2.