-
Notifications
You must be signed in to change notification settings - Fork 0
/
DateVariables.sas
171 lines (146 loc) · 5.77 KB
/
DateVariables.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
%GLOBAL YYYYMM;
%GLOBAL YYYYLM;
%GLOBAL YYYYLM2;
%GLOBAL YYYYLM3;
%GLOBAL YYYYLM4;
%GLOBAL YYYYLM5;
%GLOBAL YYYYLM6;
%GLOBAL YYYYLM7;
%GLOBAL YYYYLM8;
%GLOBAL YYYYNM;
%GLOBAL YYYYNM2;
%GLOBAL YYYYNM3;
%GLOBAL YYYYNM4;
%GLOBAL EOM;
%GLOBAL EOLM;
%GLOBAL EOLM2;
%GLOBAL EOLM3;
%GLOBAL EOLM4;
%GLOBAL EOLM5;
%GLOBAL EOLM6;
%GLOBAL BOM;
%GLOBAL BOLM;
%GLOBAL BOLM2;
%GLOBAL BOLM3;
%GLOBAL BOLM4;
%GLOBAL YYYYMMDD_EOM;
%GLOBAL YYYYMMDD_BOM;
%GLOBAL YYYYMMDD_BOLM;
%GLOBAL YYYYMMDD_BOLM2;
%GLOBAL TDBOM;
%GLOBAL TDBOLM;
%GLOBAL TDBOLM2;
%GLOBAL TDBOLM3;
%GLOBAL TDBOLM4;
%GLOBAL TDEOM;
%GLOBAL TDEOLM;
%GLOBAL TDEOLM2;
%GLOBAL TDEOLM3;
%GLOBAL TDEOLM4;
%GLOBAL TDEOLM5;
%GLOBAL TDEONM;
%GLOBAL TDBONM;
%GLOBAL TDEOLM12;
%GLOBAL TDEOLM24;
%GLOBAL R445BOM;
%GLOBAL R445EOM;
%GLOBAL YYYLY;
%MACRO MTLY_DATES(YEAR, MONTH);
DATA _NULL_;
CALL SYMPUT("YYYYMM", PUT(MDY(&MONTH, 1, &YEAR), YYMMN.));
CALL SYMPUT("YYYYLM", PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -1), YYMMN.));
CALL SYMPUT("YYYYLM2", PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -2), YYMMN.));
CALL SYMPUT("YYYYLM3", PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -3), YYMMN.));
CALL SYMPUT("YYYYLM4", PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -4), YYMMN.));
CALL SYMPUT("YYYYLM5", PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -5), YYMMN.));
CALL SYMPUT("YYYYLM6", PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -6), YYMMN.));
CALL SYMPUT("YYYYLM7", PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -7), YYMMN.));
CALL SYMPUT("YYYYLM8", PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -8), YYMMN.));
CALL SYMPUT("YYYYNM", PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), 1), YYMMN.));
CALL SYMPUT("YYYYNM2", PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), 2), YYMMN.));
CALL SYMPUT("YYYYNM3", PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), 3), YYMMN.));
CALL SYMPUT("YYYYNM4", PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), 4), YYMMN.));
CALL SYMPUT('EOM', INTNX("MONTH", MDY(&MONTH, 1, &YEAR), 0, "END"));
CALL SYMPUT('EOLM', INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -1, "END"));
CALL SYMPUT('EOLM2', INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -2, "END"));
CALL SYMPUT('EOLM3', INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -3, "END"));
CALL SYMPUT('EOLM4', INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -4, "END"));
CALL SYMPUT('EOLM5', INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -5, "END"));
CALL SYMPUT('EOLM6', INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -6, "END"));
CALL SYMPUT('BOM', INTNX("MONTH", MDY(&MONTH, 1, &YEAR), 0, "BEGINNING"));
CALL SYMPUT('BOLM', INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -1, "BEGINNING"));
CALL SYMPUT('BOLM2', INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -2, "BEGINNING"));
CALL SYMPUT('BOLM3', INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -3, "BEGINNING"));
CALL SYMPUT('BOLM4', INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -4, "BEGINNING"));
CALL SYMPUT('YYYYMMDD_EOM', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), 0, "END"), YYMMDDN.));
CALL SYMPUT('YYYYMMDD_BOM', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), 0, "BEGINNING"), YYMMDDN.));
CALL SYMPUT('YYYYMMDD_BOLM', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -1, "BEGINNING"), YYMMDDN.));
CALL SYMPUT('YYYYMMDD_BOLM2', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -2, "BEGINNING"), YYMMDDN.));
CALL SYMPUT('TDBOM', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), 0, "BEGINNING"),YYMMDD10.), ''''));
CALL SYMPUT('TDBOLM', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -1, "BEGINNING"),YYMMDD10.), ''''));
CALL SYMPUT('TDBOLM2', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -2, "BEGINNING"),YYMMDD10.), ''''));
CALL SYMPUT('TDBOLM3', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -3, "BEGINNING"),YYMMDD10.), ''''));
CALL SYMPUT('TDBOLM4', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -4, "BEGINNING"),YYMMDD10.), ''''));
CALL SYMPUT('TDEOM', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), 0, "END"), YYMMDD10.), ''''));
CALL SYMPUT('TDEOLM', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -1, "END"), YYMMDD10.), ''''));
CALL SYMPUT('TDEOLM2', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -1, "END"), YYMMDD10.), ''''));
CALL SYMPUT('TDEOLM3', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -1, "END"), YYMMDD10.), ''''));
CALL SYMPUT('TDEOLM4', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -1, "END"), YYMMDD10.), ''''));
CALL SYMPUT('TDEOLM5', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -1, "END"), YYMMDD10.), ''''));
CALL SYMPUT('TDEONM', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), 1, "END"), YYMMDD10.), ''''));
CALL SYMPUT('TDBONM', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), 1, "BEGINNING"),YYMMDD10.), ''''));
CALL SYMPUT('TDEOLM12', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -12, "END"), YYMMDD10.), ''''));
CALL SYMPUT('TDEOLM24', CATS('DATE''', PUT(INTNX("MONTH", MDY(&MONTH, 1, &YEAR), -24, "END"), YYMMDD10.), ''''));
/*4-4-5 Calendar*/
CALL SYMPUT('R445BOM', PUT(INTNX("R445MON", MDY(&MONTH, 1, &YEAR), 0, "BEGINNING"),DATE9.));
CALL SYMPUT('R445EOM', PUT(INTNX("R445MON", MDY(&MONTH, 1, &YEAR), 0, "END"),DATE9.));
CALL SYMPUT("YYYLY", PUT(INTNX("YEAR", MDY(&MONTH, 1, &YEAR), -1), YEAR.));
RUN;
%PUT &YYYYMM;
%PUT &YYYYLM;
%PUT &YYYYLM2;
%PUT &YYYYLM3;
%PUT &YYYYLM4;
%PUT &YYYYLM5;
%PUT &YYYYLM6;
%PUT &YYYYLM7;
%PUT &YYYYLM8;
%PUT &YYYYNM;
%PUT &YYYYNM2;
%PUT &YYYYNM3;
%PUT &YYYYNM4;
%PUT &EOM;
%PUT &EOLM;
%PUT &EOLM2;
%PUT &EOLM3;
%PUT &EOLM4;
%PUT &BOM;
%PUT &BOLM;
%PUT &BOLM2;
%PUT &BOLM3;
%PUT &BOLM4;
%PUT &YYYYMMDD_EOM;
%PUT &YYYYMMDD_BOM;
%PUT &YYYYMMDD_BOLM;
%PUT &YYYYMMDD_BOLM2;
%PUT &TDEOM;
%PUT &TDBOM;
%PUT &TDEOLM;
%PUT &TDBOLM;
%PUT &TDEONM;
%PUT &TDBONM;
%PUT &TDEOLM12;
%PUT &TDEOLM24;
%PUT &R445BOM;
%PUT &R445EOM;
%PUT &YYYLY;
%MEND MTLY_DATES;
%MTLY_DATES(2017,10); *UPDATE REPORT MONTH HERE;
%MACRO TEST();
/* print some date variables */
%PUT &YYYYMM;
%PUT &YYYYLM;
%PUT &YYYYLM2;
%PUT &YYYLY;
%MEND TEST;
%TEST(); /* print variables to log output */