Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mf_dttmfmts.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Returns the SAS format names that carry a date, datetime or time value
4
5 @details Prints a quoted, comma separated list of format NAMES, for use in
6 open code or in generated code:
7
8 if upcase(fmt) in (%mf_dttmfmts(DATE)) then fmttype='DATE';
9 else if upcase(fmt) in (%mf_dttmfmts(DATETIME)) then fmttype='DATETIME';
10 else if upcase(fmt) in (%mf_dttmfmts(TIME)) then fmttype='TIME';
11 else fmttype='NUM';
12
13 The names carry no width or decimal suffix, so strip that first (eg DATE9.
14 becomes DATE). This macro is the single source of truth for the lists -
15 mcf_getfmttype.sas builds its FCMP lookups from it.
16
17 @param [in] type DATE / DATETIME / TIME (case insensitive)
18
19 <h4> SAS Macros </h4>
20 @li mp_abort.sas
21
22 <h4> Related Macros </h4>
23 @li mcf_getfmttype.sas
24
25 @version 9.4
26 @author Allan Bowe
27**/
28
29%macro mf_dttmfmts(type);
30%local type found;
31%let type=%upcase(&type);
32%let found=0;
33/* so an empty type reaches the abort below, rather than an %eval error */
34%if %length(&type)=0 %then %let type=INVALID;
35
36%if &type=DATE %then %do;
37 %let found=1;
38 'DATE','YYMMDD','B8601DA','DAY','DDMMYY','DDMMYYB','DDMMYYC','DDMMYYD',
39 'DDMMYYN','DDMMYYP','DDMMYYS','DDMMYYx','DOWNAME','E8601DA','JULDAY',
40 'JULIAN','MMDDYY','MMDDYYB','MMDDYYC','MMDDYYD','MMDDYYN','MMDDYYP',
41 'MMDDYYS','MMDDYYx','MMYY','MMYYC','MMYYD','MMYYN','MMYYP','MMYYS','MMYYx',
42 'MONNAME','MONTH','MONYY','PDJULG','PDJULI','QTR','QTRR','WEEKDATE',
43 'WEEKDATX','WEEKDAY','WEEKU','WEEKV','WEEKW','WORDDATE','WORDDATX','YEAR',
44 'YYMM','YYMMC','YYMMD','YYMMDDB','YYMMDDC','YYMMDDD','YYMMDDN','YYMMDDP',
45 'YYMMDDS','YYMMDDx','YYMMN','YYMMP','YYMMS','YYMMx','YYMON','YYQ','YYQC',
46 'YYQD','YYQN','YYQP','YYQR','YYQRC','YYQRD','YYQRN','YYQRP','YYQRS',
47 'YYQRx','YYQS','YYQx','YYQZ','NLDATE'
48%end;
49%else %if &type=DATETIME %then %do;
50 %let found=1;
51 'DATETIME','B8601DN','B8601DT','B8601DZ','DATEAMPM','DTDATE','DTMONYY',
52 'DTWKDATX','DTYEAR','DTYYQC','E8601DN','E8601DT','E8601DZ','NLDATM'
53%end;
54%else %if &type=TIME %then %do;
55 %let found=1;
56 'TIME','B8601LZ','B8601TM','B8601TZ','E8601LZ','E8601TM','E8601TZ','HHMM',
57 'HOUR','MMSS','TIMEAMPM','TOD'
58%end;
59
60%mp_abort(iftrue=(&found=0)
61 ,mac=&sysmacroname
62 ,msg=%str(type must be DATE, DATETIME or TIME - got: &type)
63)
64
65%mend mf_dttmfmts;