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

I'm using SAS studio. The environment is Windows 10. I would to change the dataset name of an xpt file. Anyone, could you give me the code to rename the dataset?

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Renaming a dataset within the XPORT library is not possible, because of the internal sequential structure of the XPORT file.

You need to recreate the whole file:

/* create the xpt file for testing */

libname xp xport '/folders/myfolders/class.xpt';

proc copy in=sashelp out=xp;
select class air;
run;

libname xp clear;


/* how to rename a dataset */
/* assign xport library */
libname xp xport '/folders/myfolders/class.xpt';

/* create a temporary library within the WORK path */
%let wk = %sysfunc(pathname(WORK));
%let rc = %sysfunc(dcreate(temp,&wk.));
libname scratch "&wk./temp";

/* copy the contents there */
proc copy in=xp out=scratch;
run;

/* rename the dataset */
proc datasets lib=scratch nolist;
change class=class1;
quit;

/* move it back to the xport library */
proc copy in=scratch out=xp;
run;

/* deassign */
libname xp clear;

/* remove the scratch library */
/* empty it */
proc datasets library=scratch kill nolist;
quit;

libname scratch clear;

/* remove the directory */
%let rc=%sysfunc(filename(dref,&wk./temp));
%let rc=%sysfunc(fdelete(&dref.));

 

View solution in original post

12 REPLIES 12
andreas_lds
Jade | Level 19

Can you post the code reading the xpt-file?

Shim1222
Calcite | Level 5

Here is my code

 

libname XP xport "/home/masato-shimura0/mAbprogram/02-17/serumaj.xpt";

proc copy in=XP out=A; run;
andreas_lds
Jade | Level 19

You can use proc datasets with the change-statement to rename a dataset.

Shim1222
Calcite | Level 5
Thank you.
How should I modifiy my code?
Shim1222
Calcite | Level 5
This code is to open the xpt file (Unfortunately it did not work well.). I have no idea what code to rename the xpt dataset.

Thank you.
Shim1222
Calcite | Level 5
Thank you.
Yes, I want to rename xpt file itself.
Kurt_Bremser
Super User

Then use the RENAME function:

libname xp xport '/folders/myfolders/class.xpt';

data xp.class;
set sashelp.class;
run;

libname xp clear;

data _null_;
rc = rename("/folders/myfolders/class.xpt","/folders/myfolders/xxx.xpt","file");
put rc=;
run;
Shim1222
Calcite | Level 5
I confirmed that I could rename the name of xpt file itself.
Thank you.

And I want to rename the name of dataset in xpt file (dataset within the xpt library?).
Could you tell me the code?
Shim1222
Calcite | Level 5
Unfortunately, I could not store the xpt file in my library. Your code refers library "sasahelp class". I would like to refer my xpt file. Could you tell me how I can store xpt file in directed library and refer?

Thank you.
Kurt_Bremser
Super User

You do NOT store a .xpt file in a library. A SAS library is for storing datasets, views, catalogs, not for external files.

With the XPORT engine, you can treat a transport file like a SAS library, but with limitations: since it has a sequential structure, it needs to be rebuilt completely when data is written to it.

 

I used SASHELP.CLASS only as source data for creating an example xpt file.

Kurt_Bremser
Super User

Renaming a dataset within the XPORT library is not possible, because of the internal sequential structure of the XPORT file.

You need to recreate the whole file:

/* create the xpt file for testing */

libname xp xport '/folders/myfolders/class.xpt';

proc copy in=sashelp out=xp;
select class air;
run;

libname xp clear;


/* how to rename a dataset */
/* assign xport library */
libname xp xport '/folders/myfolders/class.xpt';

/* create a temporary library within the WORK path */
%let wk = %sysfunc(pathname(WORK));
%let rc = %sysfunc(dcreate(temp,&wk.));
libname scratch "&wk./temp";

/* copy the contents there */
proc copy in=xp out=scratch;
run;

/* rename the dataset */
proc datasets lib=scratch nolist;
change class=class1;
quit;

/* move it back to the xport library */
proc copy in=scratch out=xp;
run;

/* deassign */
libname xp clear;

/* remove the scratch library */
/* empty it */
proc datasets library=scratch kill nolist;
quit;

libname scratch clear;

/* remove the directory */
%let rc=%sysfunc(filename(dref,&wk./temp));
%let rc=%sysfunc(fdelete(&dref.));

 

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 12 replies
  • 2717 views
  • 4 likes
  • 3 in conversation