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.

  1. Creating a SAS dataset on unix
    1. 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;
      
    2. Run the file with the command: sas test
    3. The file will created the SAS dataset called myfile.ssd01
    4. myfile.ssd01 is the SAS dataset located in the ~userid/sas subdirectory
  2. Converting a SAS Dataset with SAS/Unix to a Portable file
    1. 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;
      
    2. Run the file with the command: sas cport . It will convert the SAS dataset myfile.ssd01 to a portable file called myfile.por
  3. 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.
  4. Converting the Portable file to a SAS dataset on the personal computer
    1. SAS portable files are not directly usable.
    2. Convert the portable file to a SAS dataset by putting myfile.por into the c:\saswin directory.
    3. 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;
      
    4. Run this program on the PC with the following commands: SAS cimport
    5. This will create a file called myfile.sd2 in the C:\saswin directory on the personal computer.
  5. Accessing the SAS dataset on the personal computer
    1. Construct a program called Readds.sas
    2. Place Readds.sas in the c:\saswin subdirectory
    3. 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

  1. Conversion on the PC of a library to a portable file
    1. Create a subdirectory called c:\saswin\portable
    2. Place the SAS dataset you wish to transfer in c:\saswin\portable
    3. 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
    4. Run the program with the command SAS lib2por
    5. This creates a portable file called newlib.por consisting of all sas datasets that have been created and stored in c:\saswin\portable.
  2. 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
  3. 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
  4. Use CIMPORT on unix to convert Portable file to a SAS Dataset
    1. 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;
      
    2. Run this program with the command: sas cimport
    3. This produces a sas dataset called create.ssd01.
  5. 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

  1. Version 5 SAS Transport files are constructed with Proc Copy and must be transformed to SAS unix datasets with Proc Copy.
  2. Move the transport file into a unix directory called ~userid/sas,
  3. 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;
    
  4. Submit the job with the command: sas procopy
  5. The SAS datasets will then be extracted from mypor and will have .ssd01 suffixes.
  6. If the dataset extracted is mydat then the extracted sas dataset will be mydat.ssd01
  7. 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.