SLEEP Function

For a specified period of time, suspends the execution of a program that invokes this function.

Category: Special
See: SLEEP Function: Windows in SAS Companion for Windows

Syntax

SLEEP(n<, unit> )

Required Argument

n

is a numeric constant, variable, or expression that specifies the number of units of time for which you want to suspend execution of a program.

Range n ≥ 0

Optional Argument

unit

specifies the unit of time in seconds, which is applied to n. For example, 1 corresponds to 1 second, .001 corresponds to 1 millisecond, and 5 corresponds to 5 seconds.

Default 1 in a Windows PC environment, .001 in other environments

Details

The SLEEP function suspends the execution of a program that invokes this function for a period of time that you specify. The program can be a DATA step, macro, IML, SCL, or anything that can invoke a function. The maximum sleep period for the SLEEP function is 46 days.

Examples

Example 1: Suspending Execution for a Specified Period of Time

The following example tells SAS to delay the execution of the DATA step PAYROLL for 20 seconds:
data payroll;
   time_slept=sleep(20,1);
   ...more SAS statements...
run;

Example 2: Suspending Execution Based on a Calculation of Sleep Time

The following example tells SAS to suspend the execution of the DATA step BUDGET until March 1, 2013, at 3:00 AM. SAS calculates the length of the suspension based on the target date and the date and time that the DATA step begins to execute.
data budget;    
   sleeptime='01mar2013:03:00'dt-'01mar2013:2:59:30'dt; 
   time_calc=sleep(sleeptime,1);
   put 'Calculation of sleep time:';
   put sleeptime='seconds';
run;
SAS writes the following output to the log:
Calculation of sleep time:
sleeptime=30 seconds

See Also

CALL Routines: