BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DmytroYermak
Lapis Lazuli | Level 10

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

8 REPLIES 8
alexal
SAS Employee

@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; 

 

DmytroYermak
Lapis Lazuli | Level 10
Thank you. Is it possible to do for several datasets in one step?
alexal
SAS Employee

@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;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

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;
DmytroYermak
Lapis Lazuli | Level 10

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;

 

Ksharp
Super User

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

@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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 11550 views
  • 1 like
  • 5 in conversation