Published on :
Macro CREATION_INTERNE

Workload Generation for Performance Testing

This code is also available in: Deutsch Español Français
Awaiting validation
The `%mp_testjob` macro is designed to test performance or maintain an active session. It initializes a temporary library in WORK, then enters a loop conditioned by the desired execution duration (`duration` parameter). In each iteration, it generates a large dataset (1 million observations) with random values, aggregates it via PROC SUMMARY, enriches it via PROC SQL, and sorts it via PROC SORT. It includes a 5-second pause between cycles. Finally, it cleans up datasets and frees the library.
Data Analysis

Type : CREATION_INTERNE


Data is algorithmically generated (`ranuni` function) within the macro. No external data dependency.

1 Code Block
Macro Variable
Explanation :
Timer initialization and creation of a unique temporary workspace (folder and libref) to isolate test data.
Copied!
1%let start_tm=%sysfunc(datetime());
2%let duration=%sysevalf(&duration);
3 
4/* create a temporary library in WORK */
5%let lib=%mf_getuniquelibref();
6%let dir=%mf_getuniquename();
7%mf_mkdir(%sysfunc(pathname(work))/&dir)
8LIBNAME &lib "%sysfunc(pathname(work))/&dir";
2 Code Block
DATA STEP Data
Explanation :
Generation of a large dataset (1M rows) containing random numbers and a repeated character string, without compression to maximize I/O.
Copied!
1DATA &lib..&ds1(compress=no );
2 DO x=1 to 1000000;
3 randnum0=ranuni(0)*3;
4 randnum1=ranuni(0)*2;
5 bigchar=repeat('A',300);
6 OUTPUT;
7 END;
8RUN;
3 Code Block
PROC SUMMARY Data
Explanation :
Execution of a descriptive statistics procedure to consume CPU and memory on the generated data.
Copied!
1PROC SUMMARY ;
2 class randnum0 randnum1;
3 OUTPUT out=&lib..&ds2;
4RUN;QUIT;
4 Code Block
PROC SQL Data
Explanation :
Use of SQL to create a new sorted table with an additional calculated column, testing the SQL engine's performance.
Copied!
1PROC SQL;
2create TABLE &lib..&ds3 as
3 select *, ranuni(0)*10 as randnum2
4from &lib..&ds1
5order BY randnum1;
6QUIT;
5 Code Block
PROC SORT
Explanation :
Sorting the resulting dataset to test sorting performance (I/O intensive).
Copied!
1PROC SORT DATA=&lib..&ds3;
2 BY descending x;
3RUN;
6 Code Block
DATA STEP
Explanation :
5-second pause in execution to simulate waiting time or reduce continuous system pressure.
Copied!
1DATA _null_;
2 call sleep(5,1);
3RUN;
7 Code Block
PROC DATASETS
Explanation :
Final cleanup: deletion of all tables created in the temporary library and release of the library assignment.
Copied!
1PROC DATASETS lib=&lib kill;
2RUN;
3QUIT;
4LIBNAME &lib clear;
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 : Allan Bowe