-
Notifications
You must be signed in to change notification settings - Fork 8
/
date_sk.sas
50 lines (40 loc) · 1.8 KB
/
date_sk.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
%macro date_sk(input, type);
/****************************************************************************
BEGIN MACRO HEADER
****************************************************************************
Name: date_sk
Author: Chris Swenson
Created: 2018-03-30
Purpose: Generate date secondary keys. In other words, convert dates
into numeric values that look like formatted dates, in either
YYYYMM or YYYYMMDD style.
Arguments: input - input date
type - format type, either YYMM or YYMMDD
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
YYYY-MM-DD III Please use this format and insert new entries above
****************************************************************************
END MACRO HEADER
****************************************************************************/
%if "&INPUT" = "" %then %do;
%put %str(E)RROR: Please specify the input date (1st argument).;
%return;
%end;
%if "&TYPE" = "" %then %do;
%put %str(E)RROR: Please specify the SK type (2nd argument): YYMM (YYYYMM) or YYMMDD (YYYYMMDD);
%return;
%end;
%else %let type = %upcase(&TYPE);
%if %index(*YYMM*YYMMDD*,*&TYPE*) = 0 %then %do;
%put %str(E)RROR: Please specify the SK type: YYMM (YYYYMM) or YYMMDD (YYYYMMDD);
%return;
%end;
%if &TYPE = YYMM %then %do;
year(&INPUT) * 100 + month(&INPUT)
%end;
%else %if &TYPE = YYMMDD %then %do;
year(&INPUT) * 10000 + month(&INPUT) * 100 + day(&INPUT);
%end;
%mend date_sk;