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!
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;
I would suggest using PROC SQL, here is an example:
proc sql noprint;
create table work.test as select * from sashelp.cars;
run;
quit;
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;
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;
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;
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;
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;
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: