Converting .trn or .stc SAS transport files into Usable STATA/SPSS/SAS Data Files

Question:
How do I convert a SAS .trn or .stc file into a different format like Stata, SPSS, Excel, ect. ?

Answer:
There are 2 answers to this FAQ. Please try the first Answer. If it does not work attempt the second answer. If neither work contact the CCSS-RS HelpDesk.

You may copy and paste most of the sample codes below. The quotation marks do not paste correctly from this FAQ into SAS editor. You must delete and re-enter the quotation marks. SAS codes are color coded, text inside quotation marks should be purple. Green text are comments

Begin by saving the .trn to a folder on your U drive while connected to the CCSS-RS servers. Remember where you save your .trn file on the servers, we will be using it later.

In SAS Editor enter the following commands, replace “PATH” and filenames your personal path locations and file names:
ANSWER 1

*GREEN TEXT DENOTES A COMMENT, intended for you to read.;
*Purpose: Dataset is of .trn format. Must import .trn file into a SAS dataset first. Once a SAS dataset has been created we can convert it into any other format like excel, SPSS, Stata, ect to run statistics on data;
*Begin by setting SAS library. Library is exact path location of where .trn file is saved;
*LIBNAME ALIAS "PATH";

LIBNAME JG "U:\Documents”;
*Above example JG is my “ALIAS” AND “U:\Documents” is my “PATH” where .trn file is saved;

*Data step below to convert .trn file into SAS dataset;
*DATA alias.newSASdatasetname;

DATA JG.EEOP1;
*ALIAS JG used above to save SAS dataset “EEOP1” to PATH “U:\Documents”

*Reference .trn file and convert to SAS dataset;
*FILENAME TRANS "FULLPATH\FILE.TRN";

FILENAME TRANS "U:\Documents\ui.trn";
RUN;


*PROC CIMPORT INFILE=TRANS LIB=ALIAS;

PROC CIMPORT INFILE=TRANS LIB=JG;
RUN;

*At this point, a new SAS dataset named EEOP1 should be saved to location “U:\Documents”;
*Make sure to check the SAS log for notes and errors;
*Directly below is example using GSS data from ICPSR GSS ICPSR. Easier for copying and pasting into SAS editor;
Example Code 1

LIBNAME JG "U:\Documents\GSS ICPSR\ICPSR_36319\DS0001";
DATA JG.GSS;
FILENAME TRANS "U:\Documents\GSS ICPSR\ICPSR_36319\DS0001\36319-0001-Data.stc";
RUN;
PROC CIMPORT INFILE=TRANS LIB=JG;
RUN;


* Resulting data set saved with name 'DA36319P1'. Apply accompanying formats with GSS data;
OPTIONS FMTSEARCH=(JG.formats);
* SAS DATA STEP. KEEP A FEW VARIABLES FOR FASTER PROCESSING;
DATA JG.GSSt1(keep=YEAR ID HRS1);
SET JG.DA36319P1(obs=50);
RUN;

*From here, use the Stat Transfer application to convert SAS dataset into Stata, Excel, SPSS, anything;

*If above suggestion is not successful, try Answer 2 below;

ANSWER 2
The code below relates to the data found at the following link. hegis data sample. If you attempt to convert this data set using Answer 1 an error will occur. Thus attempt the solution below.

*Below reference full path along with file;
*LIBNAME TRANS XPORT "PATH\TRN_FILE_NAME";

LIBNAME TRANS XPORT “U:\Documents\user files\jrg363\heg.erd8485.ed184.trn”;

*Below specifies path location of where SAS dataset from .trn file will be saved;
*LIBNAME NEW “PATH”;
LIBNAME NEW “U:\Documents\user files\jrg363”;
RUN;

*Below creates SAS dataset;
PROC COPY IN = TRANS OUT = NEW;
RUN;

*Lastly export SAS dataset to specific file type, below creates stata dataset because ‘.dta’ extension;
PROC EXPORT DATA = NEW.ED184 OUTFILE = "U:\Documents\user files\jrg363\jrg363ts.dta";
RUN;

*Below creates SPSS dataset because ‘.sav’ extension;
PROC EXPORT DATA = NEW.ED184 OUTFILE = "U:\Documents\user files\jrg363\jrg363ts.sav";
RUN;

*Below creates .csv dataset because ‘.csv’ extension;
PROC EXPORT DATA = NEW.ED184 OUTFILE = "U:\Documents\user files\jrg363\jrg363ts.csv";
RUN;

*Below full Example of importing .trn and exporting to Stata format.
Example Code 2
LIBNAME TRANS XPORT “U:\Documents\user files\jrg363\heg.erd8485.ed184.trn”;
LIBNAME NEW “U:\Documents\user files\jrg363”;
RUN;
PROC COPY IN = TRANS OUT = NEW;
RUN;
PROC EXPORT DATA = NEW.ED184 OUTFILE = "U:\Documents\user files\jrg363\jrg363ts.dta";

 

Alternative ways to converting the SAS data set into another form is to:

  • Read the newly created SAS data set with another software. Example: The STATA command for reading in a SAS dataset is as follows:
    usesas using “path\file_name”