Hello
Let's say that I want to Rename data set tbl1 (in work library) into tbl2 (in work library) then the code will be :
proc datasets library=WORK;
change tbl1=tbl2 ;
run;
Let's say that I want to Rename data set tbl1 (in permanent library R_R) into tbl2 (in permanent library R_R) then the code will be :
proc datasets library=R_R;
change tbl1=tbl2 ;
run;
My question:
Let's say that I want to COPY
data set tbl1 (in WORK library) into tbl1 (in permanent library R_R) - what is the code to do it?
Please note that the data set is very big(25 million rows and 20 columns)
and running the following code will be too heavy and not efficient
DATA R_R.tbl1;
SET WORK.tbl1;
Run;
proc delete data=WORK.tbl1;Run;
Unless your WORK and the permanent library are on the same physical disk (and you use an operating system which allows multiple links), you have to copy the whole file, either through a DATA step or the FCOPY function.
Instead of copying from WORK to anywhere else, change the final step which creates the dataset so that it is created in the permanent library in the first place.
Let's say that R_R library is in this path
/usr/local/SAS/SASUsers/LabRet/Credit_Scoring_Users/R_R
What is the FCOPY function code that is needed here?
data _null_;
rc = filename("source",pathname("work")!!"/tbl1.sas7bdat",,"recfm=n");
rc = filename("target","/usr/local/SAS/SASUsers/LabRet/Credit_Scoring_Users/R_R/tbl1.sas7bdat",,"recfm=n");
rc = fcopy("source","target");
run;
If you have XCMD enabled, you can use the UNIX system's cp or mv command; if mv finds that both locations are on the same physical filesystem, it will simply create a new directory entry and remove the old one, meaning the whole process will finish in next to no time.
proc copy in=work out=r_r;
select tbl1;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.