4. CA MICS Facilities › 4.7 Calendar Derivations › 4.7.1 Calendar Support Macro Descriptions
4.7.1 Calendar Support Macro Descriptions
CA MICS database files typically include calendar related
data elements as part of file summarization sequences. The
"average" CA MICS file key sequence includes SYSID and other
environmental descriptors (such as user ID), but end with
some combination of the timestamp-oriented data elements
YEAR, MONTH, WEEK, DAY, HOUR, and ZONE.
All of these data elements (YEAR, MONTH, WEEK, DAY, HOUR, and
ZONE) are found by calculating some function of the data
element ENDTS, End Time Stamp. ENDTS is always set by
CA MICS logic to be a SAS "datetime" value, usually printed
using the SAS DATETIME19.2 output format. ENDTS contents are
a single numeric value that represents the date and time of a
certain data source event. SAS represents any such time
stamp as a floating point number of seconds after 01JAN1960.
For more information about SAS representation of datetime
values, see the SAS product basics documentation.
It becomes necessary in CA MICS logic to extract the several
parts of ENDTS, separating ENDTS into the YEAR, MONTH, DAY,
and so on, in which the data source event occurred.
HOUR is always the integer hour of the day in which ENDTS
lies, and should not be modified. ZONE determination is
discussed later in this section. The other elements have
their own determination macros. Each element is described
next. The examples shown assume a standard Gregorian
calendar, as implemented in standard CA MICS 12-month year
support macros (SOURCE member #DWMY12/$DWMY12).
WKSTART - From CPLXDEF (complex-level default) or SITE
(unit-level override) parameter definition, the
number from the following table of the day of the
week on which a calendar week is said to begin.
The numbers in this table are identical to the
values returned by the SAS WEEKDAY function.
1 = Sunday
2 = Monday
3 = Tuesday
4 = Wednesday
5 = Thursday
6 = Friday
7 = Saturday
Example: If WKSTART is specified to be a value of
1, a calendar week begins on Sunday.
Program reference: &WKSTART
YRSTART - From ENDTS, extract the date of the first day of
the year in which ENDTS occurred, and store it into
the numeric data element YRSTART.
Example: ENDTS is 16AUG2001:14:00:00.00, 2pm on
the 16th day of August, 2001. YRSTART is
01JAN2001.
Program reference: %YRSTART
YEAR - From ENDTS, subtract 1900 from the gregorian year
(e.g., 2001), and store it into the numeric data
element YEAR.
Example: ENDTS is 16AUG2001:14:00:00.00, 2pm on
the 16th day of August, 2001. YEAR is
101.
Note: Prior to year 2000, YEAR is the 2-digit
year of the century (e.g., 98 for 1998).
Program reference: %YEAR
MONTH - From ENDTS, extract the number of the month within
the YEAR, and store it into the numeric data
element MONTH.
Example: ENDTS is 16AUG2001:14:00:00.00, 2pm on
the 16th day of August, 2001. MONTH is
8.
Program reference: %MONTH
WEEK - From ENDTS, extract the number of the week within
the YEAR, typically 1 to 54, and store that number
in the numeric data element WEEK.
A typical logic flow consists of the following:
1. Find the date associated with the datetime
value ENDTS. The data element name ENDDT is
reserved within CA MICS for storing this value.
2. Find the year start date of the year in which
ENDDT occurred. The data element name YRSTART
is reserved within CA MICS for storing this
data element. This element is the output of
invoking the %YRSTART macro.
3. Find the SAS WEEKDAY value of the year start
date.
4. WEEK is calculated as:
IF WEEKDAY(YRSTART)-&WKSTART >= 0 THEN
WEEK=INT((ENDDT-YRSTART+WEEKDAY(YRSTART)
-&WKSTART)/7+1);
ELSE WEEK=INT((ENDDT-YRSTART+WEEKDAY(YRSTART)
-&WKSTART+7)/7+1);
Example: ENDTS is 16AUG2001:14:00:00.00, 2pm on
the 16th day of August, 2001. If WKSTART
has a value of 1, which means weeks start
on Sunday, then WEEK is 33.
Program reference: %WEEK
DAY - From ENDTS, extract the number of day of the month,
and store it into the numeric data element DAY.
Example: ENDTS is 16AUG2001:14:00:00.00, 2pm on
the 16th day of August, 2001. DAY is 16.
Program reference: %DAY
Remember, these macros must be defined as both macro language
and macro statements.
Macro Macro
Language must also be defined as Statement
--------- --------
%YRSTART _YRSTART
&WKSTART _WKSTART
%YEAR _YEAR
%MONTH _MONTH
%WEEK _WEEK
%DAY _DAY