-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnaptime.sas
116 lines (95 loc) · 3.94 KB
/
naptime.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
%macro NapTime(time,date,override=N,test=N) / des='Set date/time to execute code';
/********************************************************************************
BEGIN MACRO HEADER
********************************************************************************
Name: NapTime
Author: Chris Swenson
Created: 2010-04-19
Purpose: Set date/time to execute the SAS code that follows the macro.
Useful when the user cannot schedule tasks.
Arguments: time - time to wake SAS
data - date to wake SAS
override= - N - do not override the pop-up question
Y - override the pop-up questions
test= - whether to test the macro or not, defaulted to No
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
YYYY-MM-DD III Please use this format and insert new entries above
********************************************************************************
END MACRO HEADER
********************************************************************************/
%let test=%substr(%upcase(&TEST), 1, 1);
%let override=%substr(%upcase(&OVERRIDE), 1, 1);
/* Check arguments */
%local dateinput;
%if "&time"="" %then %do;
%put %str(E)RROR: Missing time argument.;
%return;
%end;
%if "&date"="" %then %do;
%let dateinput=today();
%put NOTE: Date argument blank. Setting to today.;
%end;
%else %do;
%let dateinput="&date"d;
%end;
%if "&TEST"="" %then %do;
%put %str(E)RROR: No argument specified for TEST.;
%return;
%end;
%if %index(*N*Y*,*&TEST*)=0 %then %do;
%put %str(E)RROR: %str(I)nvalid TEST argument. Please use Y or N.;
%return;
%end;
%if %index(*N*Y*,*&OVERRIDE*)=0 %then %do;
%put %str(E)RROR: %str(I)nvalid OVERRIDE argument. Please use Y or N.;
%return;
%end;
/* Check format and set combined macro variable */
%local datetime;
%let datetime=;
data _null_;
format date date9. time time8. datetime datetime19.;
date=&dateinput;
time="&time"t;
datetime=input(compress(put(date, date9.) || ':' || put(time, time8.)), datetime19.);
call symputx('datetime', put(datetime, datetime19.));
/* Set date again in case it is not specified */
call symputx('date', put(date, date9.));
run;
/* Check if datetime macro variable was populated */
%if "&datetime"="" %then %do;
%put %str(E)RROR: Datetime format incorrect. Check the arguments.;
%return;
%end;
/* Check that the user wants to put SAS to sleep */
%if &OVERRIDE=N %then %do;
%local rusure;
%let rusure=;
%window rusure
// @20 "The code timer is set to execute the code at &time on &date.."
// @20 "This will put SAS to sleep. Do you wish to continue?"
// @20 rusure 1 attr=rev_video required=yes
// @20 "Enter Y for Yes or N for No, then hit ENTER to continue.";
%display rusure delete;
%end;
%else %if &OVERRIDE=Y %then %let rusure=Y;
/* Put SAS to sleep if yes from the user until the specified time */
%if %upcase(&rusure)=Y %then %do;
data _null_;
format datetime datetime19.;
datetime="&datetime"dt;
%if &test=N %then %do;
sleep=wakeup(datetime);
%end;
%else %do;
put "NOTE: Test run. Sleep statement would be: sleep=wakeup(" datetime ");";
%end;
run;
%if &test=N %then %do;
dm log 'clear';
%end;
%end;
%mend NapTime;