Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Resources / Research Tools Resource / Statistical Programming Support / SAS frequently Used Code / To convert SAS XPORT file to SAS data file

To convert SAS XPORT file to SAS data file

/********************************************************************
* to convert SAS XPORT file to SAS data file.sas
********************************************************************/
*Proc copy only can read a SAS XPORT file that made with Proc copy and can't read files that made with Proc cport;
*Proc cimport only can read a SAS XPORT file that made with Proc cport and can't read files that made with Proc copy;

* create sample data;
libname sasfile "c:\data";
data sasfile.test;
input a b c;
datalines;
1 26 31
1 28 28
1 30 31
2 32 31
2 34 29
;

/***********************************************************************************************
way 1: Proc Copy/Proc Copy;
***********************************************************************************************/
* create a XPORT file from a SAS dataset using Proc Copy;
libname sasfile "c:\data";  *this is where the SAS data set reside;
libname xptfile xport "c:\test.xpt";  *this is where the XPORT file will be created;
proc copy in=sasfile out=xptfile memtype=data;
select test;
run;

*convert the XPORT file back to a SAS dataset using proc step;
libname xptfile xport "c:\test.xpt";
libname sasfile2 "c:\ye\temp\";
proc copy in=xptfile out=sasfile2 memtype=data;
run;

*convert the XPORT file back to a sas dataset using data step;
 libname in xport "c:\test.xpt" /*directory path where file is located/SAS export file nam*/;
data wave1;
set in.test;
run;

/***********************************************************************************************
way 2: Proc Cport/Proc Cimport;
***********************************************************************************************/
*create a XPORT files from a sas data sets using Proc Cport;
libname sasfile "c:\data";
data sasfile.test2;
input a b c d;
datalines;
1 26 31 1
1 28 28 2
1 30 31 3
2 32 31 4
2 34 29 5
;
libname sasfile "c:\data";  *this is where the SAS dataset wiil  be created;
libname xptfile xport "c:\test2.xpt";
proc cport data=sasfile.test2 file="c:\test2.xpt";
run;

*convert the XPORT file back to a SAS data library;
libname sasfile2 "c:\ye\temp";  *this is where the SAS dataset wiil  be created;
libname xptfile xport "c:\test2.xpt"; *this is where the XPORT file reside;
proc cimport infile=xptfile library=sasfile2;
run;