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:dissertationsalary.sas7bdat.
Obs sal1996 sal1997 sal1998 sal1999 sal2000
1 10000 10500 11000 12000 12700
2 14000 16500 18000 22000 29000The 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:dissertationsalary.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:dissertationsalarylong). 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:dissertationsalarylong.sas7bdat .
data 'c:dissertationsalarylong'; 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:dissertationsalarylong'; run; proc contents data='c:dissertationsalarylong'; 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 29000The CONTENTS Procedure
Data Set Name: c:dissertationsalarylong 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:dissertationsalarylong.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
- SAS FAQ
– How do I read SAS Version 6 files using SAS
version 8, How do I convert SAS Version 6 Files to SAS Version 8 (under windows)?
– How do I convert SAS Version 8 files to SAS
version 6 Files (under windows)? - >SAS Learning Modules
– Making and using SAS Data Files (version 6)
Web notes
- See our SAS FAQfor information about
reading SAS Version 6 files using SAS
version 8 (under windows) . - See our SAS FAQ for information about
converting SAS Version 8 files to SAS
version 6 Files (under windows) .