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!

21 REPLIES 21
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.
Ok6
Calcite | Level 5 Ok6
Calcite | Level 5
Thanks for your response. I have same problem and after using the code, I got an error: "physical file does not exist". What could be responsible?
Tom
Super User Tom
Super User

@Ok6 wrote:
Thanks for your response. I have same problem and after using the code, I got an error: "physical file does not exist". What could be responsible?

This is usually caused by not using the actual name of the file.

You might simply have a typo.  Remember that on Unix file names are case sensitive.  So myfile.xpt is not the same file as MyFile.XPT.

 

You might be looking for the file in the wrong directory (or "folder").

 

You might be using the name the file has on your PC and not the name that the file has on the machine were SAS is running.  Remember if you are using a tool like SAS/Studio or Enterprise Guide to compose and submit your SAS programs that it is the machine where SAS itself is running and not the machine that is running your user interface that is important.

 

Remember when use a LIBNAME statement with the XPORT engine that SAS does not know whether your intention is to READ from the libref that is created or WRITE to it.  So the LIBNAME statement will not fail if the file does not exist.  Instead the failure will come when you try to read from the file that the libref pointed to.

Ok6
Calcite | Level 5 Ok6
Calcite | Level 5
Thanks but error persists.
Tom
Super User Tom
Super User

What. Error exactly?  What code did you run?

Did you try running the simple data step to LOOK at the file that I posted before?

data _null_;
  infile "put the name of the file you want to read here" obs=5 recfm=f lrecl=80 ;
  input;
  list;
run;

If that says the file cannot be found, then you are using the wrong name for the file.

If it can be found then make sure the content looks like a SAS XPORT file.  The lines written to the SAS log by the LIST statement should look something like this it is is a real XPORT file.

 RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0                      
 1         HEADER RECORD*******LIBRARY HEADER RECORD!!!!!!!000000000000000000000000000000  
 
 2   CHAR  SAS     SAS     SASLIB  9.4     Linux...                        12APR26:22:41:34
     ZONE  54522222545222225454442232322222466770002222222222222222222222223345533333333333
     NUMR  3130000031300000313C92009E400000C9E580000000000000000000000000001210226A22A41A34
 3         12APR26:22:41:34                                                                
 4         HEADER RECORD*******MEMBER  HEADER RECORD!!!!!!!000000000000000001600000000140  
 5         HEADER RECORD*******DSCRPTR HEADER RECORD!!!!!!!000000000000000000000000000000  
 NOTE: 5 records were read from the infile ...

 

Ok6
Calcite | Level 5 Ok6
Calcite | Level 5
Error 180-322 repeated four times
Tom
Super User Tom
Super User

@Ok6 wrote:
Error 180-322 repeated four times

To help figure out the issue we need to see the code that generated the error message.

 

Highlight the lines of text from the SAS log (including the source code, the notes and the errors) then copy them and paste them into the pop-up window you get in this forum when you press on the Insert Code button (looks like < / > ).

 

If there is any personally information (perhaps a username for example) you can convert those characters to X's before saving your message.

ballardw
Super User

@Ok6 wrote:
Thanks but error persists.

Best practice for this forum is to show the code and any messages from the log. Copy the text from the log starting with the code statements submitted that are having an issue through the end of all of the messages associated with the code. On the forum open a text box using the </> icon that appears above the message window and paste the copied text.

 

The text box is important because the software running the forum will reformat text pasted into the main message window that sometimes reduces the readability or completeness of the diagnostics that SAS often supplies.

 

In the case of "file doesn't exist" type messages common problems are spelling , case of text, actual location of the file such as attempting to use a local to your computer file where the server running SAS cannot see it. If you show the actual code and messages we can help better. Also, it would be better to start your own thread instead of adding to an older thread. The creator of the thread has options available such as marking an answer correct that others do not. If you do start your own thread you can post a link to this one to reference what has been done so far. 

Kurt_Bremser
Super User

The usual mistake that causes the "physical file does not exist" message comes from trying to read a local (residing on your PC) file in the remote (running on a server) SAS session. You must upload the file to the On Demand server first (Studio can do this) and then use the path on the server in your code. You can get the complete path through the properties of the file by right-clicking on it in the file navigation tab of SAS Studio.

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.

 

 

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

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
  • 21 replies
  • 10762 views
  • 1 like
  • 6 in conversation