PROC DATASETS - MODIFY RENAME CHANGE FORMAT Statements

Setting up the Background

SAS Code:

libname xyz 'D:\SAS_Datasets\';

data xyz.a;

amt = 5600;

run;

data xyz.b;

run;

data xyz.c;

amt = 5600;

run;

data xyz.d;

amt = 5600;

run;

<< Back to the PROC DATASETS Page.

Under this section we are going to learn how to modify or change the attributes of a SAS Datasets.

One may be interested in chaning the name of the column or changing the name of dataset itself.

Or you may want to change the format applied to a column etc.

And all those things needs to be carried out without touching the data residing in that dataset.

PROC DATASETS makes it possible by making changes directly at the metadata level.

There are different statements in PROC DATASETS pertaining to our requirements.

Those are CHANGE, MODIFY, RENAME, FORMAT etc.

SYNTAX:

proc datasets lib="libname";

CHANGE current_dataset_name = new_dataset_name;

MODIFY dataset_name;

RENAME current_column_name = new _column_name;

FORMAT column_name new_formatname_to_be_applied;

quit;

EXAMPLE:

In the following examples; it has been demonstrated

A] How to Change the name of the dataset (Rename the dataset).

B] How to alter the column attributes in the dataset.

But before moving to the actual demonstrations we will set up the environment.

Following code declares one library and creates some SAS datasets inside; just for demo purpose.

amt = 5600;

Following code is trying to change the name of one of the dataset lying in the designated library.

SAS Code: PROC DATASETS - CHANGE Statement

libname xyz 'D:\SAS_Datasets\';

proc datasets lib=xyz;

/* Changing the name of the dataset */

change a = changed_a;

quit;

Following is the output of the code above. (Note, this is just a part of the actual output).

You can observe that Dataset name 'A' has been changed to 'CHANGED_A'.

OUTPUT: PROC DATASETS - CHANGE Statement

Now lets see, how we can use PROC DATASETS for changing the column level attributes like column name, column format etc.

SAS Code: PROC DATASETS - MODIFY RENAME & FORMAT Statements

libname xyz 'D:\SAS_Datasets\';

proc datasets lib=xyz;

/* Changing the name of the column from the dataset*/

modify changed_a;

rename amt = changed_amt;

format changed_amt dollar6.;

quit;

proc contents data=xyz.changed_a;

run;

CONTENTS procedure will give following output.

One can observe that variable from dataset changed_a which was previously named as 'amt' has been renamed to 'changed_amt' also it has the format DOLLAR6. attached to it

OUTPUT: PROC DATASETS MODIFY, RENAME & FORMAT Statements