UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS FAQ
How do I transfer SAS data files from a PC to UNIX?

This FAQ will show how to transfer a SAS data file from a PC to UNIX (for example, the RS/6000 Cluster, Nicco, Aristotle, or any other UNIX computer).

If you have a SAS version 8 data file (i.e., one that ends with a .sas7bdat extension), then all you need to do is to FTP the file from your PC to your UNIX system (in BINARY mode) and you can use the file immediately.  If you have a SAS version 6 file (i.e., with a .sd2 extension) then you can follow the directions below.  Or, if you have SAS version 8 on your PC and on UNIX, you can Convert your SAS Version 6 file to a SAS version 8 Data File? and then FTP that file (in BINARY mode) to your UNIX system.

To begin, let's first create the dataset cars1.sd2 by reading in raw data instream.

LIBNAME in 'C:\carsdata';
 
DATA in.cars1;
  input MAKE $ PRICE MPG REP78 FOREIGN;
DATALINES;
AMC    4099 22 3 0
AMC    4749 17 3 0
AMC    3799 22 3 0
Audi   9690 17 5 1
Audi   6295 23 3 1
BMW    9735 25 4 1
Buick  4816 20 3 0
Buick  7827 15 4 0
Buick  5788 18 3 0
Buick  4453 26 3 0
Buick  5189 20 3 0
Buick 10372 16 3 0
Buick  4082 19 3 0
Cad.  11385 14 3 0
Cad.  14500 14 2 0
Cad.  15906 21 3 0
Chev.  3299 29 3 0
Chev.  5705 16 4 0
Chev.  4504 22 3 0
Chev.  5104 22 2 0
Chev.  3667 24 2 0
Chev.  3955 19 3 0
Datsun 6229 23 4 1
Datsun 4589 35 5 1
Datsun 5079 24 4 1
Datsun 8129 21 4 1
;
RUN;

It is always a good idea to look to see if the observations were read correctly. This can be checked with proc print as shown below.

PROC PRINT DATA=in.cars1(obs=5);
RUN;
OBS    MAKE    PRICE    MPG    REP78    FOREIGN
  1    AMC      4099     22      3         0
  2    AMC      4749     17      3         0
  3    AMC      3799     22      3         0
  4    Audi     9690     17      5         1
  5    Audi     6295     23      3         1

It is also a good idea to look at the descriptive statistics for your data, so you can cross check these results against the file that will be read on UNIX.

PROC MEANS DATA=in.cars1;
RUN;
Variable   N          Mean       Std Dev       Minimum       Maximum
--------------------------------------------------------------------
PRICE     26       6651.73       3371.12       3299.00      15906.00
MPG       26    20.9230769     4.7575042    14.0000000    35.0000000
REP78     26     3.2692308     0.7775702     2.0000000     5.0000000
FOREIGN   26     0.2692308     0.4523443             0     1.0000000
--------------------------------------------------------------------

In order to use a PC SAS data file on Unix, you need to create a SAS xport file. SAS xport files can be read on any SAS platform. To create a SAS xport file named cars2.xpt from an existing SAS system file named cars1.sd2 which is located in the C:\carsdata directory, use the following code.

LIBNAME in 'C:\carsdata';
LIBNAME out XPORT 'C:\carsdata\cars2.xpt';
 
DATA out.cars2;
  SET in.cars1;
RUN;
 
PROC CONTENTS DATA=out.cars2;
RUN;

Below is the output produced by the statements above.

CONTENTS PROCEDURE

Data Set Name: OUT.CARS2                              Observations:         .
Member Type:   DATA                                   Variables:            5
Engine:        XPORT                                  Indexes:              0
Created:       12:50 Friday, August 20, 1999          Observation Length:   40
Last Modified: 12:50 Friday, August 20, 1999          Deleted Observations: 0
Protection:                                           Compressed:           NO
Data Set Type:                                        Sorted:               NO
Label:

[output abbreviated to save space]

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

#    Variable    Type    Len    Pos
-----------------------------------
5    FOREIGN     Num       8     32
1    MAKE        Char      8      0
3    MPG         Num       8     16
2    PRICE       Num       8      8
4    REP78       Num       8     24

Note that the extensions .sd2 and .xpt ARE NOT included in the data step. Also notice that the libname out statement that writes the file cars2.xpt includes the file name. This is in contrast to the libname in statement that reads the file cars1.sd2 which does not include the file name. This is a somewhat confusing feature of SAS. The rule is this:  when reading and writing SAS System data files, the libname statement only includes the directory where the file is located. When reading and writing SAS xport files, the file name MUST be included in the libname statement.

Once the SAS xport file cars2.xpt has been created, it can be transferred to UNIX (usually by FTP). It should be noted that SAS xport files must transferred in BINARY mode. Let's assume that you transfer the file cars2.xpt to your Unix home directory. To read the SAS xport file on UNIX, and write it out as a SAS system file named cars3.ssd01 use the following syntax (note that ~/cars2.xpt means to read the file cars2.xpt from your home directory).

LIBNAME in XPORT '~/cars2.xpt';
LIBNAME out '~';
 
DATA out.cars3;
  SET in.cars2;
RUN;

Again, note that the extension .ssd01 is NOT included in the data step, nor is the extension .xpt.

It is probably a good idea to list the contents of this new file. For this, we can use proc contents.

PROC CONTENTS DATA=out.cars3;
RUN;

Below is the output produced by the proc contents procedure above.

CONTENTS PROCEDURE

Data Set Name: OUT.CARS3                              Observations:         26
Member Type:   DATA                                   Variables:            5
Engine:        V612                                   Indexes:              0
Created:       17:22 Friday, August 20, 1999          Observation Length:   36
Last Modified: 17:22 Friday, August 20, 1999          Deleted Observations: 0
Protection:                                           Compressed:           NO
Data Set Type:                                        Sorted:               NO
Label:

[output abbreviated to save space]

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

#    Variable    Type    Len    Pos
-----------------------------------
5    FOREIGN     Num       8     32
1    MAKE        Char      8      0
3    MPG         Num       8     16
2    PRICE       Num       8      8
4    REP78       Num       8     24

It is also a good idea to print the first few observations, and compute descriptive statistics for the transferred dataset, just to cross-check the results for the UNIX file with the results of the PC file (above).

PROC PRINT DATA=out.cars3;
RUN;
 
PROC MEANS DATA=out.cars3;
RUN;

Below is the output produced by the proc print and proc means statements above, confirming that the file transfer (from PC to UNIX) was successful.

OBS    MAKE    PRICE    MPG    REP78    FOREIGN
  1    AMC      4099     22      3         0
  2    AMC      4749     17      3         0
  3    AMC      3799     22      3         0
  4    Audi     9690     17      5         1
  5    Audi     6295     23      3         1
Variable   N          Mean       Std Dev       Minimum       Maximum
--------------------------------------------------------------------
PRICE     26       6651.73       3371.12       3299.00      15906.00
MPG       26    20.9230769     4.7575042    14.0000000    35.0000000
REP78     26     3.2692308     0.7775702     2.0000000     5.0000000
FOREIGN   26     0.2692308     0.4523443             0     1.0000000
--------------------------------------------------------------------

For more information


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