Using Proc Datasets for Efficiency Originally presented as a Coder’s NESUG2000 by Ken Friedman Reviewed by Karol Katz
Proc Datasets, an Overview Used to manage SAS Datasets List,change, append and repair datasets Create and maintain indexes Proc DATASETS includes all capabilities of the APPEND, CONTENTS and COPY procedures Procedure commands execute with a RUN command or another DATASETS command The procedure remains active until another procedure, dataset statement, or QUIT command is executed
LIBNAME input ‘SAS-data-library’ ; PROC DATASETS LIBRARY = input ; DATASETS commands RUN; APPEND vs SET SET command reads ALL observations from the datasets being concatenated. The APPEND command ONLY reads the observations from the dataset being appended. If the two datasets do not contain the same variable names, types or lengths, you can use the FORCE option to force the append to take place.
APPEND vs. SET PROC DATASETS; APPEND OUT = membr_b DATA = Membr_a (WHERE = (year=2004)); QUIT; RUN; DATA membr_b; SET membr_b membr_a (WHERE = (year=2004)); RUN;
CHANGE Command Used to rename one or more members within a SAS library Specify old name on left of the equals sign and new name on right The following example renames two temporary datasets PROC DATASETS ; CHANGE temp1 = Jan_Mar04 temp2 = Apr_Jun04; RUN;
Copy command To copy or move a SAS a member from one library to another To limit copying to specific members use either SELECT or EXCLUDE options To move a member from one library to another and then delete the original member, use the MOVE option LIBNAME lib1 ‘SAS-data-library1’; LIBNAME lib2 ‘SAS-data-library2’; PROC DATASETS; COPY in = lib1 out = lib2 MOVE; SELECT member1 member2; * / memtype = (data); RUN;
Modify Command Works only on one dataset at a time Allows you to change or specify formats, informats, and labels, rename variables and create and delete indexes For an existing dataset the MODIFY command is the best way to make changes because no observations are read in or written out during processing Using a data step with a set statement you can also make changes, however all oberservations are read in & written out. In a large dataset time and storage can be significant
MODIFY Example: LIBNAME input ‘SAS-data-library’ ; PROC DATASETS LIBRARY = input ; MODIFY income(LABEL=‘Household Income’); RENAME oldvar=newvar; LABEL newvar=‘originally called old’; FORMAT income comma11.2; RUN; DATASETS procedure is interactive Commands execute immediately in the order they appear Be cautious when working with this procedure