Discover More Tips and Techniques on This Blog

Showing posts with label XPORT engine. Show all posts
Showing posts with label XPORT engine. Show all posts

Transporting SAS Files using Proc Copy and or Proc Cport/Proc Cimport

When moving SAS datasets /catalogs from one type of computer to another, there are several things to be considered, such as the operating systems of the two computers, the versions of SAS and the type of communication link between the computers.

The easiest way to move SAS datasets from one system to another system is to:

Create a transport file using any SAS version.
Move the transport file to the new system.
Import the transport file on the new system.

Transport datasets are 80-byte length binary files made from SAS datasets. PROC COPY or PROC CPORT can create Transport datasets but they both create different types of transport files. Transport files can be created and read using either PROC COPY or PROC CPORT & PROC CIMPORT, but you cannot mix and match. Transport files created with PROC COPY must be read with PROC COPY; those created by PROC CPORT must be read with PROC CIMPORT.

PROC COPY uses an engine (i.e. XPORT) to create a SAS transport file. PROC COPY is used to transport SAS datasets only. It is version independent, but when used in version 8 will make only short variable names and table names (<= 8 characters).  

PROC COPY is likely to be the best choice for transporting SAS datasets (only SAS datasets).
PROC CPORT creates a different type of SAS transport file, an 80-byte binary file. PROC CPORT can transport catalogs as well as tables, but not views. It cannot transport a file to an earlier SAS version.  PROC CIMPORT is used to import transport files created with PROC CPORT.

The best choice for transporting datasets and catalogs simultaneously is to use PROC CPORT/PROC CIMPORT.
Proc COPY vs. Proc CPORT/CIMPORT

PROC CPORT/CIMPORT can be used to transport both SAS datasets and SAS catalogs. Proc CPORT and Proc CIMPORT only allow file transport from earlier version to a newer version (i.e. from SAS 6 to SAS 9) and not the opposite (i.e. from SAS 9 to SAS 8.2).

PROC COPY can be used to transfer files from newer version of SAS to an earlier release (i.e. from SAS 9 to SAS 6.0) and vice versa without any trouble. Proc Copy will not transport SAS catalogs. If you must move catalogs with PROC COPY SAS catalogs have to be converted to a SAS dataset using PROC FORMAT with the CNTLOUT option.
Note: When moving files from newer version (ex: SAS 9) to older version (ex: SAS 8.0), the long variable names in SAS 9 will get truncated to 8 bytes.

SAS Member Type
XPORT Engine with either DATA step or PROC COPY
PROC CPORT and PROC CIMPORT
Dataset
Yes
Yes
Catalogs
No
Yes

Now, here is the example about how to create transport (.xpt) files from SAS datasets.
/********************************************************************* Create a transport(.xpt) file and convert back the SAS transport (.xpt) file to SAS dataset
*********************************************************************/
%let libname=C:\Users\Sarath Annapareddy\Desktop\Transport;
* Create sample dataset;
libname sasfile "&libname";

data sasfile.test;
input var1 var2 var3;
datalines;
1 26 31
1 28 28
1 30 31
2 32 31

2 34 29
;

run;

/*******************************************************
*Create a .xpt file from a SAS dataset using Proc Copy;
/*********************************************************************/
libname sasfile "&libname"; *Location of SAS dataset; xptfile xport "&libname\test.xpt";*Location of .xpt file created;

libname
proc copy in=sasfile out=xptfile memtype=data;
select test;
run;
*Convert the .xpt file back to a SAS dataset using Proc copy;

libname xptfile xport "&libname\test.xpt";
libname sasfile2 "&libname\new\";

proc copy in=xptfile out=sasfile2 memtype=data;
run;

*Convert the .xpt file back to a sas dataset using data step;
libname datain xport "&libname\test.xpt" /*directory path where file is located/SAS export file name*/;

data xptdata;
set datain.test;
run;
************************************************************/
*Create a .xpt file from a SAS dataset using Proc Cport;
***************************************************************************/ *Proc Cport/Proc Cimport;



libname sasfile "&libname";
data sasfile.test2;
input var1 var2 var3 var4;
datalines;
1 26 31 1
1 28 28 2

1 30 31 3
2 32 31 4

2 34 29 5
;

run;

libname sasfile "&libname"; *Location of SAS dataset created;
libname xptfile xport "&libname\test2.xpt";

proc cport data=sasfile.test2 file="&libname\test2.xpt";
run;
*Convert the .xpt file back to a SAS dataset;
libname sasfile2 "&libname\new";*Location of SAS dataset created
libname xptfile xport "&libname\test2.xpt";*Location of the .xpt file;

proc cimport infile=xptfile library=sasfile2;
run;

REFERENCES:

http://www.umass.edu/statdata/software/handouts/SASTransport.pdf
http://www.ts.vcu.edu/kb/2074.html
SAS Documentation regarding Traditional Methods for creating and Importing Files in Transport files.

Disclosure:

In the spirit of transparency and innovation, I want to share that some of the content on this blog is generated with the assistance of ChatGPT, an AI language model developed by OpenAI. While I use this tool to help brainstorm ideas and draft content, every post is carefully reviewed, edited, and personalized by me to ensure it aligns with my voice, values, and the needs of my readers. My goal is to provide you with accurate, valuable, and engaging content, and I believe that using AI as a creative aid helps achieve that. If you have any questions or feedback about this approach, feel free to reach out. Your trust and satisfaction are my top priorities.