BookmarkSubscribeRSS Feed
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

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;

13 REPLIES 13
Reeza
Super User

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;


 

GS2
Obsidian | Level 7 GS2
Obsidian | Level 7
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.
Reeza
Super User
Is the AE file a public file? If so, can you share the original source? Seems like a corrupt download possibly.

GS2
Obsidian | Level 7 GS2
Obsidian | Level 7
Unfortunately it is not a public file. However, It was a file I was given. So, potentially the person who sent the file did not convert the dataset to an xpt file correctly?
Tom
Super User Tom
Super User

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;

 

GS2
Obsidian | Level 7 GS2
Obsidian | Level 7
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

Tom
Super User Tom
Super User

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

Tom
Super User Tom
Super User

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
ballardw
Super User

Show us the log for all the code you have shown.

 

 

GS2
Obsidian | Level 7 GS2
Obsidian | Level 7
My log with the errors is posted above
Reeza
Super User

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. 

 

 

 

GS2
Obsidian | Level 7 GS2
Obsidian | Level 7
Demo_J runs like it is supposed to with my original code. I tried a new file and downloaded the same file again and both do not work. So, likely this is an error on the part of the sender? Thank you
Tom
Super User Tom
Super User

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");

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 10173 views
  • 2 likes
  • 4 in conversation