SAS Data Files

SAS Data Set (Version 8 or 9)

  • Can access with SAS Version 9 or 8.  In most cases, SAS 8 can read SAS 9 files.
  • In general a file created on the Windows platform can be used on the Unix/Linux platform and vice versa but transport/xport files were invented for that purpose.
  • The SAS data set name and variable names can be up to 32 characters in length.  Blank spaces and non-alphanumeric characters other than the underscore ("_") are not allowed and names have to start with a letter or an underscore, numbers can follow.
  • The extension, .sas7bdat, is automatically assigned to the data set file name.
  • The LIBNAME syntax requires only the path of the SAS data library.

        libname in1 "E:\sasclass\data\";
     NOTE: Without specifying the engine name, SAS will choose the current version.  If you know the version of SAS file or the version you want the file to be, you should include the engine name.
        libname in1 "e:\sasclass\data";
        libname in1 v9 "e:\sasclass\data";  ** if you want to be explicit. **;


  • Can also access via Direct Reference or the SAS Explorer Window.
  • Any filename that ends in .sd7 should be renamed to .sas7bdat as SAS 9 will not read a .sd7 file.
  • Note: It is called a library because any SAS file of the specified engine type that exists in that directory/folder can be read using the libref (library reference).

 

SAS Data Set (Version 6)

  • Can access with SAS Versions 6 or higher.
  • Can access only from the platform the data set was created.
  • The SAS data set name and variable names can be no more than 8 characters in length.
  • The extension is automatically assigned to the data set.
    • SAS on Windows assigned the .sd2 file extension.
    • SAS on UNIX assigned the .ssd01 file extension.
  • The LIBNAME syntax requires only the path of the SAS data library.

        libname in2 "e:\sasclass\data\version6";
    The above works if SAS 6 data sets are the only SAS files in that directory. Otherwise, you need to specify the V6 engine:
       libname in2 v6 "e:\sasclass\data\version6";

  • Can also access via Direct Reference or the SAS Explorer Window.

 

SAS Transport/xport Format created with the xport engine

  • Can access with any version of SAS.
  • Can access from any platform.
  • The transport file name (referenced in the libname statement) follows the rules of the operating system.
  • The SAS data set name (referenced in the program) can be no more than 8 characters in length.
  • The LIBNAME syntax requires the engine specification (xport) and the full path name of the SAS transport file.

        libname in1 xport "e:\sasclass\data\newhhs.02";
    
    
        data in1.newhhs;
  • Cannot access via Direct Reference nor the SAS Explorer Window.
  • The file extension of a transport file can be anything.  It does not have to be .xpt, though that is a very popular one and is what Stata's fdause command expects.
  • Be careful when creating a transport file from a data set that has variable names longer than 8 characters as SAS may automatically truncate the names and only report it in the log as a note.
  • SAS will also truncate character variables to the first 200 characters since transport files have maximum length of 200 for character variables.
  • The data set name inside a transport/xport data file can be different.  It's a very good idea to make them the same when creating one!
  • A transport/xport data file name can contain more than one extension:  "dietdata.03Mar2005.xpt" .

SAS Transport/xport format created with PROC CPORT

  • Can access with either current or later version of SAS.
  • Can access from any platform.
  • Transport files created with PROC CPORT _have_ to be read in using PROC CIMPORT.  The xport engine will not recognize these files and neither will DBMS/Copy nor Stat/Transfer nor will Stata's fdause command.  If you receive an error when attempting to read in a transport file using the xport engine try PROC CIMPORT.

        filename inx "c:\my data\csf9805b.xpt";
    
        proc cimport data= demograph1   /* file goes into WORK library name it whatever you want */
     
         infile= inx;    /* use the fileref only */  
        run; < 
     
        /* data set work.demograph is the current version of SAS */
     
        proc contents data= demograph1;  
        run;
  • The advantages of using PROC CPORT to create a transport file are that the files are under the same restrictions as SAS version 7 or higher:
    1. Data set and variable names can be up to 32 characters
    2. Character variables can contain up to 32,767 characters
  •     filename outx "c:\my data\csf9805b.xpt";  
    
        /* file that is in the WORK library, but any libref can be specified. */
     
        proc cport data= work.demograph1 
                    file= outx;       /* use the fileref only */ 
        run;  
    
        ** Notice that the filename and the data set name do not have to be the same. **;

Another topic?

Wink Plone Theme by Quintagroup © 2013.

Personal tools
This is themeComment for Wink theme