UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS Learning Module
Making and using permanent SAS data files (version 8)

This will illustrate how to make and use SAS data files in version 8.  If you have used SAS version 6.xx, you will notice it is much easier to create and use permanent SAS data files in SAS version 8.

Consider this simple example.  This shows how you can make a SAS version 8 file the traditional way using a libname statement.  The file salary will be stored in the directory c:\dissertation\.

libname diss 'c:\dissertation\';
 
data diss.salary;
  input sal1996-sal2000 ;
  cards;
10000 10500 11000 12000 12700
14000 16500 18000 22000 29000
;
run;
Below we use proc print and proc contents to look at the file that we have created.
proc print data=diss.salary;
run;
 
proc contents data=diss.salary;
run;

We can see the data from the proc print and the proc contents shows us the data file that has been created, called c:\dissertation\salary.sas7bdat.

Obs    sal1996    sal1997    sal1998    sal1999    sal2000
 1      10000      10500      11000      12000      12700
 2      14000      16500      18000      22000      29000

The CONTENTS Procedure

Data Set Name: DISS.SALARY                                Observations:         2
Member Type:   DATA                                       Variables:            5
Engine:        V8                                         Indexes:              0
Created:       16:53 Thursday, November 16, 2000          Observation Length:   40
Last Modified: 16:53 Thursday, November 16, 2000          Deleted Observations: 0
Protection:                                               Compressed:           NO
Data Set Type:                                            Sorted:               NO
Label:
        -----Engine/Host Dependent Information-----
<output edited to save space>
File Name:                  c:\dissertation\salary.sas7bdat
Release Created:            8.0101M0
Host Created:               WIN_NT

-----Alphabetic List of Variables and Attributes-----

#    Variable    Type    Len    Pos
-----------------------------------
1    sal1996     Num       8      0
2    sal1997     Num       8      8
3    sal1998     Num       8     16
4    sal1999     Num       8     24
5    sal2000     Num       8     32

Below we make a file similar to the one above, but we will illustrate some of the new features in SAS version 8.  First, we did not need to use a libname statement.  We were able to specify the name of the data file by directly specifying the path name of the file (i.e., c:\dissertation\salarylong).  Also note that the names of the variables are over 8 characters long.  They can be up to 32 characters long.  This step creates a data file named c:\dissertation\salarylong.sas7bdat .

data 'c:\dissertation\salarylong';
  input Salary1996-Salary2000 ;
cards;
10000 10500 11000 12000 12700
14000 16500 18000 22000 29000
;
run;

Below we can do a proc print and proc contents on this data file.

proc print data='c:\dissertation\salarylong';
run;
proc contents data='c:\dissertation\salarylong';
run;
Note the names of the variables in the proc print and proc contents below SAS shows the variable name as Salary1996 showing that we used an uppercase S.  When you first create a variable, SAS will remember the case of each of the letters and show the variable names using the case you originally used.  However, you do not need to always refer to the variable as Salary1996, you can refer to it as SALARY1996 or as salary1996 or however you like, as long as the variable is spelled properly.  But this can help make your variable names more readable for outputs.
Obs    Salary1996    Salary1997    Salary1998    Salary1999    Salary2000
 1        10000         10500         11000         12000         12700
 2        14000         16500         18000         22000         29000
 
The CONTENTS Procedure
Data Set Name: c:\dissertation\salarylong                 Observations:         2
Member Type:   DATA                                       Variables:            5
Engine:        V8                                         Indexes:              0
Created:       16:53 Thursday, November 16, 2000          Observation Length:   40
Last Modified: 16:53 Thursday, November 16, 2000          Deleted Observations: 0
Protection:                                               Compressed:           NO
Data Set Type:                                            Sorted:               NO
Label:
          -----Engine/Host Dependent Information-----
<output edited to save space>
File Name:                  c:\dissertation\salarylong.sas7bdat
Release Created:            8.0101M0
Host Created:               WIN_NT

-----Alphabetic List of Variables and Attributes-----

#    Variable      Type    Len    Pos
-------------------------------------
1    Salary1996    Num       8      0
2    Salary1997    Num       8      8
3    Salary1998    Num       8     16
4    Salary1999    Num       8     24
5    Salary2000    Num       8     32

When you read and write SAS version 8 files, you can choose whether you wish to use the libname statement as we showed in our first example, or if you prefer to write out the name of the file as we showed in our second example.  Either will work with SAS version 8 data files.  If you are unsure of whether a SAS data file is a version 8 data file, you can look at the extension of the file.  If it ends with .sas7bdat then it is a version 8 data file that can be used on the PC or on UNIX.  However, if the extension is .sd2 it is a Windows SAS 6.12 file, or if the extension is .ssd01 it is a Unix SAS 6.12 file. 

For more information

Web notes


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California