BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yangzhiyong
Fluorite | Level 6

 I am a new user ,I have a extend filename xpt file example demo_j.xpt file,I want to open it ,and convert to xls file?please help me ,tks

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

SASUSER is per default opened read-only nowadays.

Use WORK or a library defined on the shared folder:

libname xp xport "/folders/myfolders/sasuser.v94/DEMO_J.XPT";
libname myfold "/folders/myfolders";

proc copy
  in=xp
  out=myfold
;
run;

Note that it is not necessary to shout at SAS to get it to work.

View solution in original post

9 REPLIES 9
ChrisNZ
Tourmaline | Level 20

How to read a XPT file, and how to create an excel file, has been discussed many times in this community.

Please search, try, and if you encounter problems, show your code and ask your question.

yangzhiyong
Fluorite | Level 6
LIBNAME XP XPORT "/folders/myfolders/sasuser.v94/DEMO_J.XPT";
PROC COPY IN=XP OUT=SASUSER;
RUN;
yangzhiyong
Fluorite | Level 6
ERROR: “SASUSER.DEMO_J.DATA” wirte is not accept
Kurt_Bremser
Super User

SASUSER is per default opened read-only nowadays.

Use WORK or a library defined on the shared folder:

libname xp xport "/folders/myfolders/sasuser.v94/DEMO_J.XPT";
libname myfold "/folders/myfolders";

proc copy
  in=xp
  out=myfold
;
run;

Note that it is not necessary to shout at SAS to get it to work.

yangzhiyong
Fluorite | Level 6
Thank you very much!
yangzhiyong
Fluorite | Level 6
please help me to write code ,let the file to save a xls file,tks!
wel51x
Calcite | Level 5

How do I do it if I have NO as in NONE access to SAS, just the .xpt file and excel?

 

I've been handed a file and told to make sense of it.

 

Doesn't seem to be a way.

wel51x
Calcite | Level 5

Answering my own question; Here's quick and dirty python code:

import pandas as pd
FILE_PATH = "(directory containing file)"
FILE = "ABC"  # filename itself (without suffix)

# Note: might need to substitute the column name of the index (in quotes) for "None" here

df = pd.read_sas(FILE_PATH + FILE + '.XPT', index=None)

df.to_csv(FILE_PATH + FILE + '.csv')

Tom
Super User Tom
Super User

The first thing you need to find out is whether the file with the XPT extension is a SAS XPORT file or a SAS CPORT file (or neither).  You can check the first 80 bytes to tell, but it is probably just easier to try one method and if it doesn't work then try the other.

It is much easier to make an XLSX file than and XLS file.  Plus they are more portable.

libname in xport 'demo_j.xpt';
libname out xlsx 'demo_j.xlsx';
proc copy inlib=in outlib=out;
run;

For a CPORT file you will need to use PROC CIMPORT instead.

proc cimport lib=out infile='demog_j.xpt';
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 9 replies
  • 28481 views
  • 3 likes
  • 5 in conversation