- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can you post the code reading the xpt-file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here is my code
libname XP xport "/home/masato-shimura0/mAbprogram/02-17/serumaj.xpt";
proc copy in=XP out=A; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can use proc datasets with the change-statement to rename a dataset.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How should I modifiy my code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So you do not want to rename a dataset within the xpt library, but the xpt file itself?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes, I want to rename xpt file itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.));