Published on :
Macro CREATION_INTERNE

SAS library write speed test macro

This code is also available in: Deutsch Español Français
Awaiting validation
The `%mp_testwritespeedlibrary` macro is designed to benchmark write performance in a SAS© library. It takes as parameters the target library (`lib`), the file size to create in GB (`size`), and the output dataset (`outds`) for the results. The macro generates a unique dataset name to avoid conflicts, creates a temporary dataset of the requested size by writing a calculated number of observations, records the start and end timestamps of the operation, then deletes the temporary dataset. Finally, it records the test details (library, start/end time, duration) in the specified output dataset.
Data Analysis

Type : CREATION_INTERNE


Data is dynamically generated by a `DATA STEP` within the macro (`do x=1 to size; output; end;`) to create a dataset of the specified size. No external data or data from SASHELP is used for the content of the tested dataset.

1 Code Block
Macro definition and initialization
Explanation :
This block defines the `%mp_testwritespeedlibrary` macro with its parameters and their default values. It declares the local macro variables `ds` (for the temporary dataset name) and `start` (for the start timestamp). It uses a `%do %until` loop with the `%mf_getuniquename()` and `%mf_existds()` macros to generate a unique dataset name that does not yet exist in the specified library, ensuring no conflicts. Finally, it captures the operation's start time via `%sysfunc(datetime())`.
Copied!
1%macro mp_testwritespeedlibrary(lib=WORK
2 ,outds=work.results
3 ,size=0.1
4)/*/STORE SOURCE*/;
5%local ds start;
6 
7/* find an unused, unique name for the new table */
8%let ds=%mf_getuniquename();
9%DO %until(%mf_existds(&lib..&ds)=0);
10 %let ds=%mf_getuniquename();
11%END;
12 
13%let start=%sysfunc(datetime());
2 Code Block
DATA STEP Data
Explanation :
This `DATA STEP` is the core of the performance measurement. It creates a dataset named `&lib..&ds` (the previously generated unique name) without compression (`compress=no`) and retaining only column `x` (`keep=x`). The `size` variable is calculated to determine the number of observations needed to reach the target size specified by the macro's `size` parameter (converted from GB to bytes and adjusted for a 'header'). The loop `do x=1 to size; output; end;` generates observations, thus simulating a significant write load.
Copied!
1DATA &lib..&ds(compress=no keep=x);
2 header=128*1024;
3 size=(1073741824/8 * &size) - header;
4 DO x=1 to size;
5 OUTPUT;
6 END;
7RUN;
3 Code Block
PROC SQL
Explanation :
This `PROC SQL` block executes a `DROP TABLE` statement to delete the temporary dataset `&lib..&ds` created previously. This is an essential cleanup step to prevent library clutter and ensure that tests are reproducible without residues from previous operations.
Copied!
1PROC SQL;
2drop TABLE &lib..&ds;
3RUN;
4 Code Block
DATA STEP Data
Explanation :
This `DATA STEP` creates the final `&outds` dataset, which contains the performance test results. It records the library name (`lib`), the start time (`start_dttm`), and the end time (`end_dttm`) of the write operation (formatted as `datetime19.`). The `duration_seconds` is calculated by subtracting the start time from the end time, providing a direct measure of write speed.
Copied!
1DATA &outds;
2 lib="&lib";
3 start_dttm=put(&start,datetime19.);
4 end_dttm=put(datetime(),datetime19.);
5 duration_seconds=end_dttm-start_dttm;
6RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright (c) 2001-2006 Rodney Sparapani (from `_version.sas`), licensed under GNU General Public License. The macro's HELP block also references 'Copyright 2010-2023 HMS Analytical Software GmbH'.