BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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;

 

 

5 REPLIES 5
Ksharp
Super User
proc copy in=R_R out=WORK;
select tbl_A;
run;
Amir
PROC Star

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.

Patrick
Opal | Level 21

 

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;
Kurt_Bremser
Super User

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.

SASKiwi
PROC Star

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 5 replies
  • 381 views
  • 3 likes
  • 6 in conversation