Using PROC DATASETS to Modify Variables - SAS Programming

PROC DATASETS is a procedure that you definitely should become acquainted with.It can accomplish a number of "housekeeping" chores very efficiently. Without it,you would need additional DATA steps and considerable programming.Some of the PROC DATASETS tasks include:copying, deleting, and renaming SAS data sets, renaming variables, changing or adding formats and labels, and appending data sets to other data sets.

Here is an example in which you modify descriptive information on some variables in a SAS data set.Suppose you want to rename variables X and Y, add a label to variable HT,and assign a format to variable DOB .First, here is the inefficient way to do it.

Example– INEFFICIENT

LIBNAME libref 'SAS_data_library';
DATA NEW;
SET libref.OLD (RENAME=(X=NEWX Y=NEWY));
LABEL HT='Height of Subject';
FORMAT DOB MMDDYY8.;
RUN;

This does the trick, but you have to create a new data set to get it done. Not necessary.You can affect all the changes you need, and save considerable time too, by using PROC DATASETS to work directly on the existing data set as follows:

Example– EFFICIENT

LIBNAME libref 'SAS_data_library';
PROC DATASETS LIBRARY=libref;
MODIFY OLD;
RENAME X=NEWX Y=NEWY;
LABEL HT='Height of Subject';
FORMAT DOB MMDDYY8.;
RUN;

For large data sets, this can be a tremendous savings.The time used for PROC DATASETS is independent of the number of observations in the data set because you are working on the information describing the data set overall, and not on individual observations in the data set.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics