Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mp_testjob.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Runs arbitrary code for a specified amount of time
4 @details Executes a series of procs and data steps to enable performance
5 testing of arbitrary jobs.
6
7 %mp_testjob(
8 duration=60*5
9 )
10
11 @param [in] duration= the time in seconds which the job should run for. Actual
12 time may vary, as the check is done in between steps. Default = 30 (seconds).
13
14 <h4> SAS Macros </h4>
15 @li mf_getuniquelibref.sas
16 @li mf_getuniquename.sas
17 @li mf_mkdir.sas
18
19 @version 9.4
20 @author Allan Bowe
21
22**/
23
24%macro mp_testjob(duration=30
25)/*/STORE SOURCE*/;
26%local lib dir ds1 ds2 ds3 start_tm i;
27
28%let start_tm=%sysfunc(datetime());
29%let duration=%sysevalf(&duration);
30
31/* create a temporary library in WORK */
32%let lib=%mf_getuniquelibref();
33%let dir=%mf_getuniquename();
34%mf_mkdir(%sysfunc(pathname(work))/&dir)
35libname &lib "%sysfunc(pathname(work))/&dir";
36
37/* loop through until time expires */
38%let ds1=%mf_getuniquename();
39%let ds2=%mf_getuniquename();
40%let ds3=%mf_getuniquename();
41%do i=0 %to 1;
42
43 /* create big dataset */
44 data &lib..&ds1(compress=no );
45 do x=1 to 1000000;
46 randnum0=ranuni(0)*3;
47 randnum1=ranuni(0)*2;
48 bigchar=repeat('A',300);
49 output;
50 end;
51 run;
52 %if %sysevalf( (%sysfunc(datetime())-&start_tm)>&duration ) %then %goto gate;
53
54 proc summary ;
55 class randnum0 randnum1;
56 output out=&lib..&ds2;
57 run;quit;
58 %if %sysevalf( (%sysfunc(datetime())-&start_tm)>&duration ) %then %goto gate;
59
60 /* add more data */
61 proc sql;
62 create table &lib..&ds3 as
63 select *, ranuni(0)*10 as randnum2
64 from &lib..&ds1
65 order by randnum1;
66 quit;
67 %if %sysevalf( (%sysfunc(datetime())-&start_tm)>&duration ) %then %goto gate;
68
69 proc sort data=&lib..&ds3;
70 by descending x;
71 run;
72 %if %sysevalf( (%sysfunc(datetime())-&start_tm)>&duration ) %then %goto gate;
73
74 /* wait 5 seconds */
75 data _null_;
76 call sleep(5,1);
77 run;
78 %if %sysevalf( (%sysfunc(datetime())-&start_tm)>&duration ) %then %goto gate;
79
80 %let i=0;
81
82%end;
83
84%gate:
85%put time is up!;
86proc datasets lib=&lib kill;
87run;
88quit;
89libname &lib clear;
90
91
92%mend mp_testjob;