Catalog of subprograms
I tested these macros using %include syntax in the main programs
or in special-purpose test programs. When I had tested them adequately,
I adjusted the main programs to invoke these macros via the autocall
facility and the sasautos option.
annvol.sas - Volatility calculator.
Addresses Req 5 and 6.(1) of the assignment.
Illustrates use of (a) named macro parameters ("parm="), (b) call symgetn()
and call symput(), and (c) numbered variables (var1-var15).
annvol calculates annualized volatilities for a data set of time series.
For a given date, the volatility is the standard deviation of the
observations on the latest n days (Cox & Rubenstein, "Options
Markets", pp. 255-6). n is an input parameter. The input value
for a series for a given date should be a difference: the value of the
variable less the value of the same variable on the previous day, as
calculated by cchg.sas. Annualized volatility is the calculated
standard deviation multiplied by the square root of the number of
days per year, an input parameter. Using appropriate parameters,
annvol will calculate volatility for a trading calendar of 250 days
per year and 5 days per week, a standard calendar of 365 days per year,
or for a simple series of observations assumed to occur on
consecutive days.
cchg.sas - Calculate day-to-day
differences in observations.
Accommodates trading calendar or conventional calendar.
clog.sas - Computes logarithms for specified
variables.
Illustrates use of %eval().
Invoked by fx2.sas and BP-1.sas which have non-logarithmic input.
consecdays.sas - Assures no missing dates in time series.
consecdays simplifies subsequent logic by inserting dummy observations
for missing dates, assuring the series contains
consecutive dates without gaps, though the variables have missing
values on those dummy observation dates.
corrwndo.sas - Prints correlation matrix for time windows.
corrwndo addresses Reqs 4, 5.(2), and 6 of the assignment.
corrwndo loops through the input data set (which is the output of
annvol). It accommodates a trading calendar or a conventional calendar.
It extracts a time window of data on each loop, as specified by
parameters, by invoking wndo2. corrwndo invokes mkvarlist2 to list and count
variables. It invokes findavar to create unique variables for temporary
use without chancing interference with data set variables. It invokes
getdsname to create unique data set names for temporary use, and delds
to delete those temporary data sets when no longer needed. It uses proc
corr to calculate the correlation matrix into a temporary data set. It
uses proc printto to direct text output to the screen or to a file,
as specified by a parameter. It uses the "missing" option and proc print
to print the lower triangle of the correlation matrix.
cvtymdsas.sas - Converts a date stored as yyyymmdd to SAS datevalue.
BP-1.sas uses cvtymdsas to convert its input without losing information
in case of invalid dates.
deabbr.sas - Converts var1-var4 to var1 var2 var3 var4, etc.
fx2.sas and unk-1.sas use deabbr to expand lists of variable names.
I wrote these programs without awareness of the names of the input series,
arbitrarily assigning names such as "cur1-cur15".
delds.sas - Deletes a data set when you dont know its name.
If you don't know its name, then you must know the name of the variable
that contains the name of the data set.
Lore: I wrote delds for a previous project. Modular code is
reusable.
dtchk.sas - Writes err msg in log on detecting invalid date.
Used in racedtck.sas to test alternate algorithms for testing date
validity.
dtchkf.sas - Like dtchk + exception ds + replace bad date w missing.
dtchkf addresses Req 3 of the assignment.
dtchkf is an evolution of dtchk. dtchkf checks for date validity
and writes exceptions to a dataset designated for that purpose. It
replaces invalid dates with the missing value and writes an error
message to the log file.
findavar.sas - Get unused unique variable name.
getdsname.sas - Get unused unique dataset name for temporary use.
Lore: I wrote delds for a previous project. Modular code is
reusable.
mkvarlist2.sas - Make list of var names in data set.
mkvarlist2 illustrates use of (a) %global variables, (b)
%eval, (c) macro debugging options mprint,
mlogic and symbolgen, and (d) their opposites nomprint, nomlogic and
nosymbolgen. It also illustrates (e) use of %sysfunc, and (f) %put.
mkvarlist2 examines a data set and returns in global macro variables
(1) the list of all the variables in the data set,
(2) the list of the numeric variables and their number, and
(3) the list of the character variables and their number.
trimset.sas - Cuts leading & trailing
obs with all values missing.
For economy of presentation, we use trimset to remove from our
datasets leading or trailing records containing all missing values.
I found numerous "missing observations" leading and trailing useful data for
some data sets.
wndo2.sas - Selects time series data from time interval
according to parameters.
wndo2 illustrates use of %local.
|