13.1 - Reading a Single SAS Data Set

In this section, we'll review how to read data already contained in one SAS data set into another SAS data set.

Example 13.1 Section

The following program uses the DATA step's SET statement to create a temporary SAS data set called work.penngolf, which is identical to the permanent SAS data set called stat481.penngolf:

Copy the code below:

OPTIONS PS = 58 LS = 72 NODATE NONUMBER;

LIBNAME stat481 'C:\yourdrivenIfame\Stat481WC\01sasdata\sasndata';

DATA penngolf;
   set stat481.penngolf;
RUN;

PROC PRINT data = penngolf NOOBS;
   title 'The penngolf data set';
RUN;

The penngolf data set

ID

Name

Architect

Year

Type

Par

Yards

Slope

USGA

101

Toftrees

Ed Ault

1968

Resort

72

7018

134

74.3

102

Penn State Blue

Willie Park, Jr.

1921

Public

72

6525

128

72.0

103

Centre Hills

Alex Findlay

1921

Private

71

6392

128

71.2

104

Lewistown CC

 

.

Private

72

6779

125

72.3

105

State College Elks

Lowell Erdman

1973

SemiPri

71

6369

123

70.9

106

Park Hill CC

James Harrison

1966

SemiPri

70

6004

126

69.3

107

Sinking Valley CC

Ed Ault

1967

SemiPri

72

6755

132

73.4

108

Williamsport CC

A.W Tillinghast

1909

Private

71

6489

131

71.9

109

Standing Stone GC

Geoffrey Cornish

1973

SemiPri

70

6593

120

71.4

110

Bucknell GC

 

1960

SemiPri

70

6253

132

70.0

Of course, the LIBNAME statement just tells SAS that the nickname for the directory in which the permanent SAS data set resides is stat481. Now for the DATA step:

  • Because a one-level name is used, the DATA statement tells SAS to create a temporary data set called penngolf. Recall that SAS stores all temporary data sets in a temporary library called work. Therefore, we can refer to the created data set either by its one-level name penngolf, or by its two-level name work.penngolf.
  • The SET statement tells SAS to assign the data in the existing permanent SAS data set stat481.penngolf — observation by observation — to the temporary SAS data set called penngolf. Because the variables in the existing data set have already been named, no INPUT statement is necessary. In fact, if you were to include an INPUT statement, SAS would croak back at you.

That's all there is to it. Before we have you run this thing, let me confess something to you — this has got to be the silliest program around! There is really no good reason for taking a permanent SAS data set and simply turning it into a temporary SAS data set without including other statements in the DATA step to modify the data set in some way. Doing so just reduces the efficiency of your programs. Instead, you should just go ahead and use the permanent SAS data set in any procedure you want. What I am begging for here is not to let me (or anyone else!) see you mimic this kind of DATA step in your future programs. I certainly wouldn't want you to pick up any bad habits from this course.

That confession made, let's run the program! Before the program will work for you, you will, of course, need to download and save the penngolf data set (click to save!) in a convenient location on your computer. Then, launch the SAS program, and edit the LIBNAME statement so it reflects the location in which you saved the data set on your computer. Then, run  the program, and review the output to familiarize yourself with the data set that we'll work with throughout the remainder of the lesson.