Using SAS 9.4
I have received 17 SAS transport files and cannot seem to find code for how to convert these files to a SAS dataset. I have tried the code below with no success to convert one xpt, would anyone know what I am doing incorrectly? Thank you
libname sasfile “path\IHMR”;
libname xptfile xport “path\IHMR\ae.xpt” access=readonly;
proc copy inlib=xptfile outlib=sasfile;
run;
Code looks correct. What errors do you get?
@GS2 wrote:
Using SAS 9.4
I have received 17 SAS transport files and cannot seem to find code for how to convert these files to a SAS dataset. I have tried the code below with no success to convert one xpt, would anyone know what I am doing incorrectly? Thank you
libname sasfile “path\IHMR”;
libname xptfile xport “path\IHMR\ae.xpt” access=readonly;
proc copy inlib=xptfile outlib=sasfile;
run;
NOTE: SAS initialization used: real time 40.26 seconds cpu time 3.56 seconds 1 libname sasfile 'path\IHMR'; NOTE: Libref SASFILE was successfully assigned as follows: Engine: V9 Physical Name: path\IHMR 2 libname xptfile xport 'path\IHMR\ae.xpt' access=readonly; NOTE: Libref XPTFILE was successfully assigned as follows: Engine: XPORT Physical Name: path\IHMR\ae.xpt 3 proc copy inlib=xptfile outlib=sasfile; NOTE: Writing HTML Body file: sashtml.htm 4 run; NOTE: Input library XPTFILE is sequential. ERROR: File XPTFILE.ALL. is not a SAS data set. NOTE: Statements not processed because of errors noted above. NOTE: PROCEDURE COPY used (Total process time): real time 8.18 seconds cpu time 0.57 seconds NOTE: The SAS System stopped processing this step because of errors.
Are you sure the file is an XPORT format file?
Look at the top of the file to see:
data _null_;
infile 'path\IHMR\ae.xpt' lrecl=80 recfm=f obs=5;
input;
list;
run;
5 data _null_;
6 infile 'path\IHMR\Data_112921\ae.xpt'
6 ! lrecl=80 recfm=f obs=5;
7 input;
8 list;
9 run;
NOTE: The infile 'path\IHMR\Data_112921\ae.xpt' is:
Filename=path\IHMR \Data_112921\ae.xpt,
RECFM=F,LRECL=80,File Size (bytes)=240,
Last Modified=07Jan2022:14:22:53,
Create Time=05Jan2022:09:18:36
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9--
1 HEADER RECORD*******LIBV8 HEADER RECORD!!!!!!!000000000000000000000000000000
2 CHAR SAS SAS SASLIB 9.1 WIN..... 07JAN22:14:22:54
ZONE 54522222545222225454442232322222544000002222222222222222222222223344433333333333
NUMR 3130000031300000313C92009E10000079E0000000000000000000000000000007A1E22A14A22A54
3 07JAN22:14:22:54
NOTE: 3 records were read from the infile 'path\IHMR\Data_112921\ae.xpt'.
NOTE: DATA statement used (Total process time):
real time 0.25 seconds
cpu time 0.10 seconds
Above is the log after running the code
So you don't have an XPORT file. That format only supports SAS V5 transport files.
Instead you have the modified format that requires you use to SAS supplied macros to convert. For some reason rather than generating a new engine that could work with longer names and longer variables they created SAS macros.
Use %XPT2LOC to convert your file into SAS dataset(s).
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/movefile/p1tp8gighlgeifn173i6kzw2w3bu.htm
Your file appears truncated.
After the first three records you should see HEADER records to indicate the start of an actual dataset.
Let's make an example transport file using the macros and see what the beginning of it looks like:
filename xxx temp;
%loc2xpt(libref=sashelp,memlist=class,filespec=xxx,format=V9);
data _null_;
infile xxx recfm=f lrecl=80 obs=7;
input;
list;
run;
Results:
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 1 HEADER RECORD*******LIBV8 HEADER RECORD!!!!!!!000000000000000000000000000000 2 CHAR SAS SAS SASLIB 9.1 WIN..... 10JAN22:12:58:52 ZONE 54522222545222225454442232322222544000002222222222222222222222223344433333333333 NUMR 3130000031300000313C92009E10000079E0000000000000000000000000000010A1E22A12A58A52 3 10JAN22:12:58:52 4 HEADER RECORD*******MEMBV8 HEADER RECORD!!!!!!!000000000000000001600000000140 5 HEADER RECORD*******DSCPTV8 HEADER RECORD!!!!!!!000000000000000000000000000000 6 CHAR SAS CLASS SASDATA 9.1 WIN.....10JAN22:12:58:52 ZONE 54522222444552222222222222222222222222225454454232322222544000003344433333333333 NUMR 313000003C133000000000000000000000000000313414109E10000079E0000010A1E22A12A58A52 7 10JAN22:12:58:52 Student Data
Show us the log for all the code you have shown.
1. Try reading in another XPT file and see if that works for you. If not, you have an issue with SAS. The link to an example NHANES xpt file is there for you.
2. If it works, try redownloading the file you were sent by your colleague and uncompress it (if zipped). If that fails, then you have a bad file and I'd ask whomeever sent it to you to recreate the file and resend it.
Your original code will not work on V8/V9 versions of transport files, which is what your truncated ae.xpt file was.
You need to use the %XPT2LOC() macro to convert instead.
libname sasfile "path\IHMR";
%xpt2loc(libref=sasfile,filespec="path\IHMR\ae.xpt");
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.