DATA Step, Macro, Functions and more

Renaming a dataset during a proc datasets

Accepted Solution Solved
Reply
Regular Contributor
Posts: 210
Accepted Solution

Renaming a dataset during a proc datasets

Hi all,

Is it possible to copy datasets and rename them simultaneously? I have coded it but the prog failed (.

 

proc datasets library=rawdata nolist;
copy out=work;
change work.ex_test=ex work.lb_test=lb work.suppex_test=suppex work.sv_text=sv work.tv_test=tv;
run;

Thank you!

 


Accepted Solutions
Solution
‎09-13-2017 09:32 AM
Super User
Posts: 10,618

Re: Renaming a dataset during a proc datasets

Posted in reply to DmytroYermak

Yes. I think so.

 

proc datasets library=work nolist;  
   change ex_test=ex
 lb_test=lb 
suppex_test=suppex 
sv_test=sv 
tv_test=tv;
quit;

View solution in original post


All Replies
SAS Employee
Posts: 493

Re: Renaming a dataset during a proc datasets

Posted in reply to DmytroYermak

@DmytroYermak,

 

I would suggest using PROC SQL, here is an example:

 

proc sql noprint; 
  create table work.test as select * from sashelp.cars; 
run; 
quit; 

 

Regular Contributor
Posts: 210

Re: Renaming a dataset during a proc datasets

Thank you. Is it possible to do for several datasets in one step?
SAS Employee
Posts: 493

Re: Renaming a dataset during a proc datasets

Posted in reply to DmytroYermak

@DmytroYermak,

 

Sure,

 

proc sql noprint; 
  create table work.test as select * from sashelp.cars; 
  create table work.test2 as select * from sashelp.baseball;
run; 
quit; 
proc print data=test; run;
proc print data=test2; run;
Super User
Super User
Posts: 9,216

Re: Renaming a dataset during a proc datasets

Posted in reply to DmytroYermak

Why do you have SDTM domains called _test in the first place?  Seems like that is your problem.  Anyways, no, you need to generate the code:

data _null_;
  set sashelp.vtable (where=(libname="WORK"));
  call execute('data work.'||strip(tranwrd(memname,"_TEST",""))||'; set work.'||strip(memname)||'; run;');
run;
Super User
Posts: 10,618

Re: Renaming a dataset during a proc datasets

Posted in reply to DmytroYermak

Once you copy all the tables into a library like WORK.

It is easy to rename the table name.

 

 

data ex_test;
 set sashelp.class;
run;
data suppex_test;
 set sashelp.class;
run;


data _null_;
 set sashelp.vmember(where=(libname='WORK')) end=last;
 if _n_=1 then call execute('proc datasets library=work nolist nodetails;change ');
 call execute(catt(memname,'=',scan(memname,1,'_')));
 if last then call execute(';quit;');
run;
Regular Contributor
Posts: 210

Re: Renaming a dataset during a proc datasets

[ Edited ]

Actually, I tried several times and here it is the result. It works but is it correct?

 

proc datasets library=rawdata nolist; 
    copy out=work;
run;
proc datasets nolist; 
    change ex_test=ex lb_test=lb suppex_test=suppex sv_test=sv tv_test=tv;
run;

 

Solution
‎09-13-2017 09:32 AM
Super User
Posts: 10,618

Re: Renaming a dataset during a proc datasets

Posted in reply to DmytroYermak

Yes. I think so.

 

proc datasets library=work nolist;  
   change ex_test=ex
 lb_test=lb 
suppex_test=suppex 
sv_test=sv 
tv_test=tv;
quit;
Super User
Super User
Posts: 7,860

Re: Renaming a dataset during a proc datasets

Posted in reply to DmytroYermak

DmytroYermak wrote:

Actually, I tried several times and here it is the result. It works but is it correct?

 

proc datasets library=rawdata nolist; 
    copy out=work;
run;
proc datasets nolist; 
    change ex_test=ex lb_test=lb suppex_test=suppex sv_test=sv tv_test=tv;
run;

 


That will work, but there may be side effects.

For example if there is already a table named WORK.EX_TEST it will be over written by the COPY step.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 668 views
  • 1 like
  • 5 in conversation