BookmarkSubscribeRSS Feed
u58975985
Calcite | Level 5

I am a new user. Can anyone explain to me how to import an XPT file into SAS OnDemand Studio? Thanks!

13 REPLIES 13
Tom
Super User Tom
Super User

To move an XPT file into SAS/Studio the first step is UPLOAD the file to the server where the SAS Session SAS/Studio is using is running.

 

For us to help you convert the XPT file into a SAS dataset you need to explain what TYPE of file the XPT file is.  SAS has two main transport formats it supports.  The files produced by PROC CPORT and those using the published transport format that is support by the XPORT libname engine (for dataset that comply with the older restrictions of SAS version 5 and 6 on variable names and character variable lengths)  or the SAS supplied %LOC2XPT and %XPT2LOC macros for SAS datasets that use longer variables names or longer character variables.

u58975985
Calcite | Level 5
I don't actually know what type of XPT files I have. They are files provided by a federal agency (CDC NHANES). Is there anyway to tell from the files?
Tom
Super User Tom
Super User

You should write to the NIH and ask them to update their documentation to explain WHAT TYPE of SAS transport file they are providing.  They just seem to mention XPT and "transport file" on their web page.  Neither that extension nor that phase helps distinquish.

 

But they are using the old SAS version 5 transport files.  So use a LIBNAME statement with the XPORT engine.

You could use PROC COPY.

libname nhanes xport 'demo_j.xpt';
proc copy inlib=nhanes out=work; run;

Or since they include only one dataset per file just a data step.

libname nhanes xport 'demo_j.xpt';
data demo_j;
  set nhanes.demo_j;
run;

 

u58975985
Calcite | Level 5
Thank you. I really appreciate your help.
Ksharp
Super User

Open your XPT file with Notepad or Notepad++.

Ksharp_0-1669771900904.png

Ksharp_1-1669772042223.png

 

Tom
Super User Tom
Super User

Note there is no need to use NOTEPAD+, just use a data step.

data _null_;
  infile 'myfile.xpt' recfm=f lrecl=80 obs=3 ;
  input;
  list;
run;

Plus you left out the CPORT transport file format.  There is no reason someone could not create a file using PROC CPORT and name the file with .XPT extension. And frequently they do.

 

 

Ksharp
Super User
Tom,
" CPORT transport file format " is not a real XPT file . FDA would not accept it
As you said , federal agency (CDC NHANES) is usually prefer V5 XPT ,not V8 XPT file.
Tom
Super User Tom
Super User

@Ksharp wrote:
Tom,
" CPORT transport file format " is not a real XPT file . FDA would not accept it
As you said , federal agency (CDC NHANES) is usually prefer V5 XPT ,not V8 XPT file.

 The XPT extension has no fixed file format associated with it.   The CPORT transport file is a transport file. That is the point I was making. Whether or not the FDA would accept it does not matter.   

Ksharp
Super User
That is not ture.
In the Pharamacy field ,Especially for sas programmer ,you only can use v5(most time) or v8 xpt file,
Not the file generated by PROC CPORT (which can make any suffix ,like .xpt .bat .tom .ksharp).

If you are in other field other than Pharmacy, you can use PROC CPORT to transport your sas datasets, but in Pharmacy ,you can't .
Tom
Super User Tom
Super User

@Ksharp wrote:
That is not ture.
In the Pharamacy field ,Especially for sas programmer ,you only can use v5(most time) or v8 xpt file,
Not the file generated by PROC CPORT (which can make any suffix ,like .xpt .bat .tom .ksharp).

If you are in other field other than Pharmacy, you can use PROC CPORT to transport your sas datasets, but in Pharmacy ,you can't .

I have been in the field for 30 years and I can tell you have seen thousands of CPORT files of clinical dataset that have been created with .XPT as the file extension.

Ksharp
Super User
OK.
Then Why did federal agency (CDC NHANES / FDA) usually posted V5 XPT ,not the file generated by PROC CPORT ?
Since the file generated by PROC CPORT has many advantage than V5 XPT (like V8 XPT,no limited 8-byte variable name,no limited 200 of character variable).
Then Why did SAS create a new macro %loc2xpt to create V8 XPT ,since there is already PROC CPORT ?
Tom
Super User Tom
Super User

@Ksharp wrote:
OK.
Then Why did federal agency (CDC NHANES / FDA) usually posted V5 XPT ,not the file generated by PROC CPORT ?
Since the file generated by PROC CPORT has many advantage than V5 XPT (like V8 XPT,no limited 8-byte variable name,no limited 200 of character variable).
Then Why did SAS create a new macro %loc2xpt to create V8 XPT ,since there is already PROC CPORT ?

More non-sequiturs.

 

The reason that the FDA requested V5 transport files is they prefer to use published standard formats.  SAS published to format of the V5 transport files.  And when SAS enhanced the format to support longer names and longer variables they published that format also.  (Why the heck SAS generates these file using macros instead of making an libname engine I have no idea)  So again the FDA would prefer the receive either of the two formats that SAS has published the specification of.  But whether or not the FDA accepts a particular file format is not  really at all related to the question of what type of file someone has sent you when it is named with an XPT extension or they call it a "transport file".

 

XPT as an extension is not determinative of the type of file.  Unlike a file with an extension of XLSX or XLS where you are 99% sure that the file is an Excel workbook.  When you have a file with a name 'XPT' or someone says they are sending your a "transport file" you have to always check to be sure what type of file they have actually sent you.

 

The NIH publishes NHANES data using V5 transport file format.  And they use the XPT as the file naming convention on the NHANES site, but that fact was not readily obvious from the WORDS they published on the site.  "The proof of the pudding is in the eating",  so for the files with NHANES data you have to actually attempt to read (or at least examine) the file to be confident of the file format.

 

Perhaps if I write it as code it will be easier to understand?

'XPT' ne 'V5 Transport file'
'XPT' ne 'CPORT Transport file'
'XPT' ne '%loc2xpt() generated transport file'
'Transport file' ne 'V5 Transport file'
'Transport file' ne 'CPORT Transport file'
'Transport file' ne '%loc2xpt() generated transport file'

 

Ksharp
Super User
Tom,
"But whether or not the FDA accepts a particular file format is not really at all related to the question of what type of file someone has sent you when it is named with an XPT extension or they call it a "transport file". "

Yes. You can use the transport file generated by PROC CPORT at anytime anywhere , as long as you tell receiver to use PROC CIMPORT to import it , that is also called transport file. But that is not standard and not official and can't submit it to FDA .

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 13 replies
  • 5914 views
  • 1 like
  • 3 in conversation