*Copyright @ www.mycsg.in;
What does PROC DATASETS do
`proc datasets` is used to manage SAS datasets and libraries efficiently
It can copy, rename, append, and modify datasets without always rewriting all observations through a DATA step
It is especially useful for metadata and dataset management tasks
Copy datasets from one library to another library
The `copy` statement copies selected datasets from one library to another
Here we copy `class` and `cars` from `sashelp` to `work`
proc datasets; copy in=sashelp out=work; select class cars; run; quit;
Copy Code
View Log
SAS Log
proc datasets; Directory Libref WORK Engine V9 Physical Name C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Filename C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Member # Name Type File Size Last Modified 1 CLASS DATA 128KB 17/04/2026 06:08:57 2 FEMALES DATA 128KB 17/04/2026 06:08:56 3 FORMATS CATALOG 17KB 17/04/2026 06:08:31 4 MALES DATA 128KB 17/04/2026 06:08:56 5 SASMACR CATALOG 5KB 17/04/2026 05:58:44 6 TEMPLAT ITEMSTOR 201KB 17/04/2026 06:08:51 copy in=sashelp out=work; select class cars; run; NOTE: Copying SASHELP.CLASS to WORK.CLASS (memtype=DATA). NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.CLASS has 19 observations and 5 variables. NOTE: Copying SASHELP.CARS to WORK.CARS (memtype=DATA). NOTE: There were 428 observations read from the data set SASHELP.CARS. NOTE: The data set WORK.CARS has 428 observations and 15 variables. quit; NOTE: PROCEDURE DATASETS used (Total process time): real time 0.03 seconds cpu time 0.03 seconds
Inspect `class` and `cars` in the WORK library and confirm that they were copied successfully
View Data
Dataset View
Rename a dataset in a library
The `change` statement renames an existing dataset
Only the dataset name changes the data values remain the same
proc datasets library=work; change class=class_new; run; quit;
Copy Code
View Log
SAS Log
proc datasets library=work; Directory Libref WORK Engine V9 Physical Name C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Filename C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Member # Name Type File Size Last Modified 1 CARS DATA 192KB 17/04/2026 06:08:57 2 CLASS DATA 128KB 17/04/2026 06:08:57 3 FEMALES DATA 128KB 17/04/2026 06:08:56 4 FORMATS CATALOG 17KB 17/04/2026 06:08:31 5 MALES DATA 128KB 17/04/2026 06:08:56 6 SASMACR CATALOG 5KB 17/04/2026 05:58:44 7 TEMPLAT ITEMSTOR 201KB 17/04/2026 06:08:57 8 TEST DATA 128KB 17/04/2026 06:08:57 change class=class_new; run; NOTE: Changing the name WORK.CLASS to WORK.CLASS_NEW (memtype=DATA). quit; NOTE: PROCEDURE DATASETS used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
View Data
Dataset View
Get the attributes of a dataset
The `contents` statement within PROC DATASETS can be used to view metadata and optionally write it to an output dataset
This is similar in purpose to PROC CONTENTS
proc datasets library=work; contents data=class_new out=cont01; run; quit;
Copy Code
View Log
SAS Log
proc datasets library=work; Directory Libref WORK Engine V9 Physical Name C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Filename C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Member # Name Type File Size Last Modified 1 CARS DATA 192KB 17/04/2026 06:08:57 2 CLASS_NEW DATA 128KB 17/04/2026 06:08:57 3 FEMALES DATA 128KB 17/04/2026 06:08:56 4 FORMATS CATALOG 17KB 17/04/2026 06:08:31 5 MALES DATA 128KB 17/04/2026 06:08:56 6 SASMACR CATALOG 5KB 17/04/2026 05:58:44 7 TEMPLAT ITEMSTOR 201KB 17/04/2026 06:08:57 8 TEST DATA 128KB 17/04/2026 06:08:58 contents data=class_new out=cont01; run; NOTE: The data set WORK.CONT01 has 5 observations and 41 variables. quit; NOTE: PROCEDURE DATASETS used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
View Data
Dataset View
Append two datasets
`append` adds observations from one dataset to the end of another dataset
The dataset on `base=` is updated by adding rows from the dataset on `data=`
Before appending the datasets
View Data
Dataset View
proc datasets library=work; append base=males data=females; run; quit;
Copy Code
View Log
SAS Log
proc datasets library=work; Directory Libref WORK Engine V9 Physical Name C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Filename C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Member # Name Type File Size Last Modified 1 CARS DATA 192KB 17/04/2026 06:08:57 2 CLASS_NEW DATA 128KB 17/04/2026 06:08:57 3 CONT01 DATA 144KB 17/04/2026 06:08:58 4 FEMALES DATA 128KB 17/04/2026 06:08:56 5 FORMATS CATALOG 17KB 17/04/2026 06:08:31 6 MALES DATA 128KB 17/04/2026 06:08:56 7 SASMACR CATALOG 5KB 17/04/2026 05:58:44 8 TEMPLAT ITEMSTOR 201KB 17/04/2026 06:08:59 9 TEST DATA 128KB 17/04/2026 06:08:59 append base=males data=females; run; NOTE: Appending WORK.FEMALES to WORK.MALES. NOTE: There were 9 observations read from the data set WORK.FEMALES. NOTE: 9 observations added. NOTE: The data set WORK.MALES has 19 observations and 5 variables. quit; NOTE: PROCEDURE DATASETS used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
After the append step the dataset `males` contains the original male rows followed by the rows from `females`
View Data
Dataset View
Add labels to variables
Get contents before applying labels to the variables
data class; set sashelp.class; run; proc contents data=class out=cont_before; run;
Copy Code
View Log
SAS Log
data class; set sashelp.class; run; NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.CLASS has 19 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds proc contents data=class out=cont_before; run; NOTE: The data set WORK.CONT_BEFORE has 5 observations and 41 variables. NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
Add labels to variables using PROC DATASETS
proc datasets library=work; modify class; label name="Name of the student" age="Age (Years)" height="Height (inches)"; run; quit;
Copy Code
View Log
SAS Log
proc datasets library=work; Directory Libref WORK Engine V9 Physical Name C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Filename C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Member # Name Type File Size Last Modified 1 CARS DATA 192KB 17/04/2026 06:08:57 2 CLASS DATA 128KB 17/04/2026 06:09:00 3 CLASS_NEW DATA 128KB 17/04/2026 06:08:57 4 CONT01 DATA 144KB 17/04/2026 06:08:58 5 CONT_BEFORE DATA 144KB 17/04/2026 06:09:00 6 FEMALES DATA 128KB 17/04/2026 06:08:56 7 FORMATS CATALOG 17KB 17/04/2026 06:08:31 8 MALES DATA 128KB 17/04/2026 06:08:59 9 SASMACR CATALOG 5KB 17/04/2026 05:58:44 10 TEMPLAT ITEMSTOR 201KB 17/04/2026 06:08:59 11 TEST DATA 128KB 17/04/2026 06:09:00 modify class; label name="Name of the student" age="Age (Years)" height="Height (inches)"; run; NOTE: MODIFY was successful for WORK.CLASS.DATA. quit; NOTE: PROCEDURE DATASETS used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
Get contents after applying labels to the variables
proc contents data=class out=cont_after; run;
Copy Code
View Log
SAS Log
proc contents data=class out=cont_after; run; NOTE: The data set WORK.CONT_AFTER has 5 observations and 41 variables. NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
Compare `cont_before` and `cont_after` and confirm that the labels were updated without recreating the dataset in a DATA step
View Data
Dataset View
Remove labels for all variables
Get contents before removing labels
proc contents data=class out=cont_before; run;
Copy Code
View Log
SAS Log
proc contents data=class out=cont_before; run; NOTE: The data set WORK.CONT_BEFORE has 5 observations and 41 variables. NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
Remove labels using PROC DATASETS
proc datasets library=work; modify class; attrib _all_ label=" "; run; quit;
Copy Code
View Log
SAS Log
proc datasets library=work; Directory Libref WORK Engine V9 Physical Name C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Filename C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Member # Name Type File Size Last Modified 1 CARS DATA 192KB 17/04/2026 06:08:57 2 CLASS DATA 192KB 17/04/2026 06:09:00 3 CLASS_NEW DATA 128KB 17/04/2026 06:08:57 4 CONT01 DATA 144KB 17/04/2026 06:08:58 5 CONT_AFTER DATA 144KB 17/04/2026 06:09:00 6 CONT_BEFORE DATA 144KB 17/04/2026 06:09:01 7 FEMALES DATA 128KB 17/04/2026 06:08:56 8 FORMATS CATALOG 17KB 17/04/2026 06:08:31 9 MALES DATA 128KB 17/04/2026 06:08:59 10 SASMACR CATALOG 5KB 17/04/2026 05:58:44 11 TEMPLAT ITEMSTOR 201KB 17/04/2026 06:09:00 12 TEST DATA 128KB 17/04/2026 06:09:00 modify class; attrib _all_ label=" "; run; NOTE: MODIFY was successful for WORK.CLASS.DATA. quit; NOTE: PROCEDURE DATASETS used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
Get contents after removing labels
proc contents data=class out=cont_after; run;
Copy Code
View Log
SAS Log
proc contents data=class out=cont_after; run; NOTE: The data set WORK.CONT_AFTER has 5 observations and 41 variables. NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
View Data
Dataset View
Add formats for variables
Get contents before applying formats
data class; set sashelp.class; run; proc contents data=class out=cont_before; run;
Copy Code
View Log
SAS Log
data class; set sashelp.class; run; NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.CLASS has 19 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds proc contents data=class out=cont_before; run; NOTE: The data set WORK.CONT_BEFORE has 5 observations and 41 variables. NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
Add formats to variables using PROC DATASETS
proc datasets library=work; modify class; format height weight 8.2; run; quit;
Copy Code
View Log
SAS Log
proc datasets library=work; Directory Libref WORK Engine V9 Physical Name C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Filename C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Member # Name Type File Size Last Modified 1 CARS DATA 192KB 17/04/2026 06:08:57 2 CLASS DATA 128KB 17/04/2026 06:09:01 3 CLASS_NEW DATA 128KB 17/04/2026 06:08:57 4 CONT01 DATA 144KB 17/04/2026 06:08:58 5 CONT_AFTER DATA 144KB 17/04/2026 06:09:01 6 CONT_BEFORE DATA 144KB 17/04/2026 06:09:01 7 FEMALES DATA 128KB 17/04/2026 06:08:56 8 FORMATS CATALOG 17KB 17/04/2026 06:08:31 9 MALES DATA 128KB 17/04/2026 06:08:59 10 SASMACR CATALOG 5KB 17/04/2026 05:58:44 11 TEMPLAT ITEMSTOR 201KB 17/04/2026 06:09:01 12 TEST DATA 128KB 17/04/2026 06:09:01 modify class; format height weight 8.2; run; NOTE: MODIFY was successful for WORK.CLASS.DATA. quit; NOTE: PROCEDURE DATASETS used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
Get contents after applying formats
proc contents data=class out=cont_after; run;
Copy Code
View Log
SAS Log
proc contents data=class out=cont_after; run; NOTE: The data set WORK.CONT_AFTER has 5 observations and 41 variables. NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
Compare `cont_before` and `cont_after` and confirm that format metadata is now attached to `height` and `weight`
View Data
Dataset View
Remove formats for variables
Get contents before removing formats
proc contents data=class out=cont_before; run;
Copy Code
View Log
SAS Log
proc contents data=class out=cont_before; run; NOTE: The data set WORK.CONT_BEFORE has 5 observations and 41 variables. NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
Remove formats using PROC DATASETS
proc datasets library=work; modify class; format height weight; run; quit;
Copy Code
View Log
SAS Log
proc datasets library=work; Directory Libref WORK Engine V9 Physical Name C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Filename C:\Users\curio\AppData\Local\Temp\SAS Temporary Files\_TD24912_MYCSG-LENOVOAIO_ Member # Name Type File Size Last Modified 1 CARS DATA 192KB 17/04/2026 06:08:57 2 CLASS DATA 192KB 17/04/2026 06:09:01 3 CLASS_NEW DATA 128KB 17/04/2026 06:08:57 4 CONT01 DATA 144KB 17/04/2026 06:08:58 5 CONT_AFTER DATA 144KB 17/04/2026 06:09:01 6 CONT_BEFORE DATA 144KB 17/04/2026 06:09:02 7 FEMALES DATA 128KB 17/04/2026 06:08:56 8 FORMATS CATALOG 17KB 17/04/2026 06:08:31 9 MALES DATA 128KB 17/04/2026 06:08:59 10 SASMACR CATALOG 5KB 17/04/2026 05:58:44 11 TEMPLAT ITEMSTOR 201KB 17/04/2026 06:09:01 12 TEST DATA 128KB 17/04/2026 06:09:02 modify class; format height weight; run; NOTE: MODIFY was successful for WORK.CLASS.DATA. quit; NOTE: PROCEDURE DATASETS used (Total process time): real time 0.00 seconds cpu time 0.01 seconds
Get contents after removing formats
proc contents data=class out=cont_after; run;
Copy Code
View Log
SAS Log
proc contents data=class out=cont_after; run; NOTE: The data set WORK.CONT_AFTER has 5 observations and 41 variables. NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.03 seconds cpu time 0.01 seconds
View Data
Dataset View
Key points to remember
`proc datasets` is designed for dataset and library management tasks
It can often change metadata more efficiently than rewriting data in a DATA step
Common uses include copying renaming appending and modifying dataset attributes