Converting SAS Files between Unix and PC
These notes were
adapted from a document by Robert Jaffe at NYU
I. Moving from Unix to the PC
SAS datasets are not directly transferrable from one operating
system to another. They must be converted to portable
files with SAS prior to movement from unix to
the portable computer. A good reference for this is
Cody, R.P.and Smith, J.K. (1991). Applied Statistics and
the SAS Programming Language, 3rd ed., Englewood Cliffs:
Prentice Hall,Inc.
pp.271-278, offer the following code for
converting a SAS dataset called myfile in the u1/userid/sas
unix directory to a portable file called myfile.por. This
portable file, called myfile.por, may be downloaded to the
portable computer for converstion there to a SAS dataset.
- Creating a SAS dataset on unix
- Construct a file called test.sas.
This SAS program file should be ascii on unix and
contain the following command syntax:
title 'Creation of SAS Dataset called myfile.ssd01 on Unix';
title3 file='~userid/sas/test.sas';
libname inp '~userid/sas';
data inp.myfile;
input a b c;
datalines;
1 2 3
3 4 4
5 3 4
proc print;
run;
- Run the file with the command: sas test
- The file will created the SAS dataset called
myfile.ssd01
- myfile.ssd01 is the SAS dataset located in
the ~userid/sas subdirectory
- Converting a SAS Dataset with SAS/Unix to
a Portable file
- Construct a file called cport.sas containing
the following commands:
LIBNAME MYLIB '~userid/sas';
Filename Trans '~userid/sas/myfile.por';
PROC CPORT DATA=MYLIB.myfile FILE=TRANS;
run;
- Run the file with the command: sas cport
.
It will convert the SAS dataset myfile.ssd01
to a portable file called myfile.por
- Download the file to the PC.
Use the FTP client application on the PC to download the portable file.
Be sure to transfer in binary.
- Converting the Portable file to a SAS dataset
on the personal computer
- SAS portable files are not directly usable.
- Convert the portable file to a SAS dataset by
putting myfile.por into the c:\saswin directory.
- Construct a file called cimport.sas containing the
following commands.
title 'Conversion of Transport library To SAS Dataset';
libname input 'c:\saswin';
filename tranfile 'c:\saswin\myfile.por';
proc cimport file=tranfile library=input;
run;
- Run this program on the PC with the following commands:
SAS cimport
- This will create a file called myfile.sd2 in
the C:\saswin directory on the personal computer.
- Accessing the SAS dataset on the personal computer
- Construct a program called Readds.sas
- Place Readds.sas in the c:\saswin subdirectory
- Readds.sas should contain the following commands:
Title 'Accessing the SAS Dataset';
Libname input c:\saswin';
Data new;
Set myfile;
Proc print;
run;
/* Your statistical procedures may follow this line */
Proc freq;
run;
II. Moving SAS Files from the PC to Unix
- Conversion on the PC of a library to a portable file
- Create a subdirectory called c:\saswin\portable
- Place the SAS dataset you wish to transfer in c:\saswin\portable
- Write a program called lib2por.sas that
includes the following statements
Title 'Creation of SASwin Transport library on the PC';
libname inpp 'c:\saswin\portable';
filename tranfile 'c:\saswin\portable\newlib.por';
proc cport library=inpp file=tranfile;
run;
This program will convert the SAS dataset(s) stored
in c:\saswin\portable to a new sas portable library
called newlib.por
- Run the program with the command SAS lib2por
- This creates a portable file called newlib.por
consisting of all sas datasets that have been
created and stored in c:\saswin\portable.
- Upload newlib.por to the your account on the
Unix system
Using the FTP client, the
upload has to be performed using the binary option
- Convert the Portable SAS file to an accessible
SAS dataset on Unix as follows:
1. Make a subdirectory is your account called sas
a. Check your path with the pwd command
- Use CIMPORT on unix to convert Portable file to a
SAS Dataset
- Create a file called cimport.sas containing
the following code
libname oldlib '~userid/sas';
filename trans '~userid/sas/newlib.por';
proc cimport data=oldlib.create file=trans;
run;
- Run this program with the command: sas cimport
- This produces a sas dataset called create.ssd01.
- Access the SAS dataset on unix with the following
SAS command syntax:
libname inpp '~userid/sas';
data one;
set inpp.create;
proc print;
run;
III. Conversing SAS v5 transport file to SAS dataset on Unix
- Version 5 SAS Transport files are constructed with Proc
Copy and must be transformed to SAS unix datasets with
Proc Copy.
- Move the transport file into a unix directory called
~userid/sas,
- Setup the following Proc Copy syntax in a file called
procopy.sas
title 'Conversion of SAS v 5 Transport file to SAS unix datset';
libname inp xport '~userid/sas/mypor';
libname outp '~userid/sas';
proc copy in=inp out=outp;
run;
- Submit the job with the command: sas procopy
- The SAS datasets will then be extracted from
mypor and will have .ssd01 suffixes.
- If the dataset extracted is mydat then the
extracted sas dataset will be mydat.ssd01
- Access mydat.ssd01 with the following program
libname inpp '~userid/sas';
data one;
set inpp.mydat;
proc print;
run;
This program will print the data in the dataset.