using proc datasets for efficiency originally presented as a coder’s corner @ nesug2000 by ken...
TRANSCRIPT
![Page 1: Using Proc Datasets for Efficiency Originally presented as a Coder’s Corner @ NESUG2000 by Ken Friedman Reviewed by Karol Katz](https://reader036.vdocuments.net/reader036/viewer/2022083004/56649d9e5503460f94a87e1d/html5/thumbnails/1.jpg)
Using Proc Datasets for Efficiency
Originally presented as a Coder’s Corner @ NESUG2000 by
Ken Friedman
Reviewed by Karol Katz
![Page 2: Using Proc Datasets for Efficiency Originally presented as a Coder’s Corner @ NESUG2000 by Ken Friedman Reviewed by Karol Katz](https://reader036.vdocuments.net/reader036/viewer/2022083004/56649d9e5503460f94a87e1d/html5/thumbnails/2.jpg)
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
![Page 3: Using Proc Datasets for Efficiency Originally presented as a Coder’s Corner @ NESUG2000 by Ken Friedman Reviewed by Karol Katz](https://reader036.vdocuments.net/reader036/viewer/2022083004/56649d9e5503460f94a87e1d/html5/thumbnails/3.jpg)
LIBNAME input ‘SAS-data-library’ ;PROC DATASETS LIBRARY = input ;DATASETS commandsRUN;
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.
![Page 4: Using Proc Datasets for Efficiency Originally presented as a Coder’s Corner @ NESUG2000 by Ken Friedman Reviewed by Karol Katz](https://reader036.vdocuments.net/reader036/viewer/2022083004/56649d9e5503460f94a87e1d/html5/thumbnails/4.jpg)
APPEND vs. SETPROC 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;
![Page 5: Using Proc Datasets for Efficiency Originally presented as a Coder’s Corner @ NESUG2000 by Ken Friedman Reviewed by Karol Katz](https://reader036.vdocuments.net/reader036/viewer/2022083004/56649d9e5503460f94a87e1d/html5/thumbnails/5.jpg)
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;
![Page 6: Using Proc Datasets for Efficiency Originally presented as a Coder’s Corner @ NESUG2000 by Ken Friedman Reviewed by Karol Katz](https://reader036.vdocuments.net/reader036/viewer/2022083004/56649d9e5503460f94a87e1d/html5/thumbnails/6.jpg)
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;
![Page 7: Using Proc Datasets for Efficiency Originally presented as a Coder’s Corner @ NESUG2000 by Ken Friedman Reviewed by Karol Katz](https://reader036.vdocuments.net/reader036/viewer/2022083004/56649d9e5503460f94a87e1d/html5/thumbnails/7.jpg)
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
![Page 8: Using Proc Datasets for Efficiency Originally presented as a Coder’s Corner @ NESUG2000 by Ken Friedman Reviewed by Karol Katz](https://reader036.vdocuments.net/reader036/viewer/2022083004/56649d9e5503460f94a87e1d/html5/thumbnails/8.jpg)
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