How can I use PROC COPY in SAS? Can you provide an example? 2

How can I use PROC COPY in SAS? Can you provide an example?

PROC COPY is a SAS procedure that allows users to make exact copies of SAS data sets, catalogs, or entire libraries. It can also be used to rename, delete, or move SAS objects within a library. This procedure is useful for creating backups of data, transferring data between libraries, and organizing data sets. An example of using PROC COPY would be to create a copy of a data set called “Sales_2019” in a new library called “Backup_Library” using the following syntax: PROC COPY IN = ‘Work’ OUT = ‘Backup_Library’ DATA = ‘Sales_2019’; RUN; This will create an exact copy of the “Sales_2019” data set in the new library, allowing for easy access and manipulation of the data.

Use PROC COPY in SAS (With Example)


You can use the PROC COPY statement in SAS to copy a dataset from one library to another.

This statement uses the following basic syntax:

proc copyin=folder1 out=folder2 memtype=data;
    select my_data;
run;

Here is what each statement does:

  • IN: The library where the dataset currently exists
  • OUT: The library to copy the dataset to
  • MEMTYPE: Specifies that only dataset should be copied
  • SELECT: The name of the dataset to copy

The following step-by-step example shows how to use PROC COPY in practice to copy a dataset from one library to another.

Step 1: Create the Dataset

First, let’s create the following dataset called my_data that contains information about various basketball players:

/*create dataset*/
data my_data;
    input team $ points assists;
    datalines;
Mavs 14 9
Spurs 23 10
Rockets 38 6
Suns 19 4
Kings 30 4
Blazers 19 6
Lakers 22 14
Heat 19 5
Magic 14 8
Nets 27 8
;
run;

/*view dataset*/
proc printdata=my_data;

Step 2: Save the Dataset in One Library

Next, we’ll use the LIBNAME statement to specify the library where our dataset should be saved:

/*define library where dataset should be saved*/
libname folder1 '/home/u13181/folder1/';

/*save dataset to library called folder1*/
data folder1.my_data;
    set my_data;
run;

If I navigate to my folders and files, I can see that my_data has indeed been saved in folder1:

Step 3: Use PROC COPY to Copy the Dataset to Another Library

Next, I can use the PROC COPY statement to copy this dataset from folder1 to folder2:

/*define library where dataset should be copied to*/
libname folder2 '/home/u13181/folder2/';

/*copy my_data to library called folder2*/ 
proc copyin=folder1 out=folder2 memtype=data;
    select my_data;
run;

If I navigate to my folders and files once again, I can see that my_data has indeed been copied to folder2:

Note: When using PROC COPY, the dataset you are copying will still remain in the original library that it came from.

The following tutorials explain how to perform other common tasks in SAS:

Cite this article

stats writer (2024). How can I use PROC COPY in SAS? Can you provide an example?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-proc-copy-in-sas-can-you-provide-an-example/

stats writer. "How can I use PROC COPY in SAS? Can you provide an example?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-proc-copy-in-sas-can-you-provide-an-example/.

stats writer. "How can I use PROC COPY in SAS? Can you provide an example?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-proc-copy-in-sas-can-you-provide-an-example/.

stats writer (2024) 'How can I use PROC COPY in SAS? Can you provide an example?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-proc-copy-in-sas-can-you-provide-an-example/.

[1] stats writer, "How can I use PROC COPY in SAS? Can you provide an example?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can I use PROC COPY in SAS? Can you provide an example?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top