I am a new user. Can anyone explain to me how to import an XPT file into SAS OnDemand Studio? Thanks!
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.
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;
Open your XPT file with Notepad or Notepad++.
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 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 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 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'
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: