East Carolina University
Department of Psychology
While I generally prefer to keep my data in plain text files in directories unknown to SAS before I point to them with an INFILE statement, one can use SAS to organize data files and other files into libraries known to SAS. Try the following little exercise:
Creating a SAS Library
Create a folder on your hard drive which will serve as a SAS library. I created the folder D:\SAS\SASdata.
Double-click the LIBRARIES icon in the Explorer window in SAS (which appears on the left hand side when you boot up SAS, but I usually close it to give me more screen space for the editor, log, and output windows).
Right click in the resulting window and select NEW.
In the New Library window enter "Sol" in the name field. Leave the Engine at "Default," but you may want to drop down the menu there to see the various engines available. Use the BROWSE key to point at the directory you just created to house SASdata files. Check "Enable at startup." OK.

Entering Data Into a Member of the Library
An icon for the library you
created should appear in the Explorer Libraries window.

Double-click the icon for the
library in which you wish enter a data file. Right click in the
resulting window and select NEW, TABLE, OK.
You get a VIEWTABLE window, like a spreadsheet.

Right click on the header of the leftmost, "A," column and
click Data, Column Attributes. In the Name field, enter "Shots." In the
Label field enter "Shots of Scotch consumed." Select Type = Numeric . Close.

Do the same for Column B, using the Name "Errors," Label "Typographic Errors."
Enter into the data cells the
data as shown below.

Close the window (X in upper right corner). Tell SAS Yes, you want to save the changes. In the SAVE AS window,
double click the Sol icon to point at that library and give a MEMBER NAME of "Scotch." Click SAVE.

The new data file will be added to the library.
After creating the Scotch data member, run the following program as an example of how to read in a Library Data File:
LIBNAME
sol
'D:\SAS\SASdata'
;
Data tipsy; Set
sol.Scotch;
Proc
Corr; var shots errors; run;
The LIBNAME points SAS to the location of SASdata on my hard drive. Be sure that your LIBNAME points to the correct name and location of your library.
The SET command has an argument of library_name.member_name. Note that the names of variables are included in the library data file, you do not have to include them in an INPUT statement. This can be quite handy if you will be using a data file many times.
It is rather inefficient to use DATA and SET. More efficient would be to point to the SAS data file in a PROC statement, like this:
LIBNAME
sol
'D:\SAS\SASdata'
;
proc corr
data=sol.Scotch; var shots errors; run;
You can also create SAS Library Data Files by using the SAS Import Wizard to convert another type of data file. For example, I had an Excel spreadsheet with salary faculty for faulty. To convert this Excel file into an SAS Library Data File, I simply did the following:
Within SAS, I clicked File, Import Data. I told SAS that the data to be imported was in an Excel file, then I pointed at the file on my hard drive, I told it to put it in the library named sol, member (name) EPA_Salaries05, FINISH. The SAS data file then appeared in my library.

Another way to create an SAS data file is to use a library dot member name in the DATA statement. Consider the following program:
LIBNAME
sol
'D:\SAS\SASdata'
; Note that the data statement identifies a system file with library name
Sol and member name XlogY. After you run this program you will find a new member in the
Sol library. That member will be named XlogY and will include the data from this program, both the X, Y data that followed the Cardsstatement and the log-transformed X data created in the DATA step.
Using a SAS Data File Obtained From Another Person First, copy it into the folder to which LIBNAME will
point. The file should a name something like this: NAME.sas7bdat.
Submit code like this to find out what is in the SAS data file.
LIBNAME
sol
'D:\SAS\SASdata'
; You will get a list of the variable names and some other useful information.
Data
Sol.XlogY; input x y @@;
2 10 2 9 2 8 3 9 3 8 5 8 8 7 12 8 17 6
Proc
Means skewness; var x y log_x;
Proc
Corr nosimple; var x log_x; with y; run;
Proc CONTENTS
data=sol.NAME;run;

Contact Information for the Webmaster,
Dr. Karl L. Wuensch
This page most recently revised on 3. December 2007.