Hello
Let's say that I want to rename data set WORK.tbl_A to WORK.tbl_B
Data tbl_A;
Input ID Name$ Weight;
cards;
2 A 2
4 B 3
7 D 5
;
run;
proc datasets library=work;
change tbl_A=tbl_B;
run;
proc sql;
select *
from tbl_B
;
quit;
Let's say that I want to rename data set R_R.tbl_A into WORK.tbl_A .
What is the way to do it?
When say "Rename data set" does it mean that there is a new data set name in same library?
I know that in this case I can run following code but I ask if there is a better more quick way
Data WORK.tbl_A;
set R_R.tbl_A;
Run;
Hi,
Normally, in my experience, when a file (of any description) is renamed, its location remains the same. If you want the library to change from R_R to work then that means the location has changed and so it sounds like you want to move the data set and not rename it.
Do you want to move the data set from library R_R to work or do you want to copy the data set from library R_R to work so that the original is still in library R_R?
So, move, or copy, or something else?
Thanks & kind regards,
Amir.
options dlcreatedir;
libname rr "%sysfunc(pathname(work))\test";
data rr.tbl_a(index=(name/unique));
set sashelp.class;
run;
proc datasets library=work nolist;
copy
in=rr
out=work
index=yes
constraint=yes
move
;
select tbl_a;
run;
contents data=work.tbl_a;
run;
quit;
IF you work on UNIX and
IF your libraries are on the same physical device(*)
then you can use the operating system's mv command, which only creates a new directory entry and removes the old one, without touching the file itself.
*) this can be any kind of virtual disk, it only needs to be mounted as one device in the system's filesystem.
In all other cases, you have to create a new file and delete the old one, moving the whole mass of data.
With all due respect, you need to describe correctly what you are doing first before looking for better solutions. As other posters have noted, you want to move or copy a dataset between libraries, not rename them (although you could do both). If you get your description right, then you'll have a much better chance of finding the better solution you want, by for example searching in SAS documentation.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.