The SAS System as a Tool for the Financial Systems Auditor Ferrell

advertisement
The SAS System as a Tool for the Financial Systems Auditor
Ferrell Drewry
SAS Institute Inc.
INTRODUCTION
auditing programs written in SAS software"
however the software does have the general
capabilities necessary for performing audit tasks.
The intent of this paper is to show that SAS
software can be effectively used as generalized
audit software provided that a library of audit
programs has been developed. The end product
is an audit software package that allows auditors
to spend more time analyzing the results of the
audit tests
rather than
coding the SAS
statements necessary to perform the audit tests.
The programs and ex~mples that have been
developed with SAS software can be found in the
appendices of this paper.
During the 1960s, businesses began to use
computers to process their accounting data. The
first computerized accounting systems relied on
batch processing: batches of transactions from
source documents were posted to files of
accounting data which were stored on magnetic
tapes or disks.
Because the
number of
transactions per batch was small and source
documents were readily available, auditors of
batch processed systems' could rely on manual
audit
tests
designed
to
du'plicate
the
computerized system's functions. 1
This paper is intended for auditors and SAS
programmers that suppor:t the audit staff. It is
assumed that the reader has a basic knowledge of
data
processing,
auditing,
and
SAS
programming. With respect to the programs for
statistical sampling, no attempt is made to
familiarize the reader with the concepts of
statistics or the with the pros and cons of
various
sampling
methods.
References
to
approp6ate texts are made as these programs are
covered.
Throughout the 1970s and early 1980s, the price
of computers and related hardware dropped
dramatically. In addition, computer technology
has advanced such that it is now feasible to have
several hundred people accessing data in, adding
data to, and altering data in files on a computer
at the same time. Although batch processing is
still being used, some newer financial systems.
employ data base technology to provide on-line,
real ti'me access to accou_nting data.
Source
documents are being replace~ by- fill-in-the-blank
screens on computer terminals and the volume of
transactrons has increased.
As a
result,
auditors a-re finding that computerized financial
systems are becoming more complex and that they
can
no
longer
rely
on manual
auditing
techniques. 2
Although the SAS System operates under several
operating systems, the auditing programs that
have been' d-eveloped in conjunction with this
paper are designed to be executed under OS/MVS
or MVS/XA from IBM. Some programs have the
additional requirement of only being able to
execute interactively under TSO which is usually
available on MVS systems. One factor that limits
the programs to these operating systems is the
use of SAS macros within the programs. The
macro facility
has
not
been
implemented
completely on the other operating systems
supported by SAS software.
Generalized software has been developed_ for
auditing I~rge, complex financial accounting
systems. Development of software for auditing
has been concurrent with the evolution of
computerized financial systems. Early auditing
software packages were developecj in the same
third-generation computer languages (COBOL,
RPG
II,
ASSEMBLER) as the financial systems.
These packages handled specific audit tasks and
required significant programming expertise to
modify them for new audit tasks. J
TASKS PERFORMED
SOFTWARE
Later versions of generalized audit software
packages were developed using fourth-generation
BY GENERALIZED AUDIT
Before developing a library of auditing program
for use with SAS software, the tasks to be
performed by these programs must be identified.
Then, the features that the generalized audit
software needs in order to perform the audit
tasks can be identified.
languages (CULPRIT, EASYTRIEVE, MARK IV).
These new languages are designed to allow novice
or casual computer users easy access to
computerized data.
Audit software packages
written in a fourth-generation language consist
of a library of auditing programs that can be
easily adapted to a specific business environment
by an auditor with only limited programming
knowledge. 4
It is appropriate to ask 'What' is auditing?' before
deciding on the requirements for the audit
software. "Auditing in its entirety is made up of
two functions, both closely concerned with
evidence. The first is the evidence gathering
function;
the second is that of evidence
evaluation. "S- ,
With respf1;ct to computerized
accounting
systems,
the
auditor
will
be
extracting data in machine readable form and
verifying its accuracy.
The SAStt; System is a fourth-generation language
that is installed on over 10,000 mainframe
computers in 55 countries.
Although SAS
software is popular, it is not generally used for
auditing applications. This is due to the fact
that there is no readily available library of
489
required to extract data from files when there
are multiple record layouts within the same file.
Specifically, the auditor will need:
to test the accu racy of the data
The format used to store the data in the record
can also affect the auditor's ability to extract the
data with generalized audit software. The
software must be capable of handling many
different
data
types:
character,
numeric,
binary, etc. Again, existing audit software can
handle the more common formats found on any
given operating system.
to determine the attributes of the data
to compare groups of data for consistency
to summarize the data for overall review
to select items for more thorough testing.
6
The audit programs in the appendix of this paper
do not include any programs for extracting data
from accounting files because of the high degree
of variation that will be encountered in those
files.
However, it should be noted that SAS
software can handle most types of data in files
that use standard access methods. Although an
interface between SAS software and IMS data
bases is available, there are few other interfaces
betw~n SAS software and data base systems.
Accounting data in data base files may have to be
written to an intermediate file that uses a
standard access method.
These audit tasks can be accomplished with
generalized audit software that has the following
capabilities:
to extract 'data from many types of files
to subset, merge" and/or transform the data
to analyze and perform calculations on the
data
to permit statistical sampling of the data
to report summary data.
I nstead of devising a progam to handle extracting
data from a wide variety of files,
it is
recommended that an EDP specialist prepare the
necessary SAS statements to read the file. The
auditor could then use these'statements in his
program to obtain the data values without having
to know the physical layout of the data within the
7
Trend analysis, project scheduling, automatic
creation of confirmations are examples of
additional features found in existing audit
softwa re packages.
file.
The remainder of this paper is devoted to
describing in more detail the features that are
r'equired for audit software as outlined above and
to
showing
how
these
features
can
be
implemented with the SAS System.
For example, consider a trial balance file that has
three types of records in the same file: a record
for the accQunt description, one or more records
for the current transactions, and a record that
contains the balances of the pr'ior 13 'months. The
record layouts for this file are in Figure 1 .. Note
that the record format that applies is determined
by the record type field on each record. The
following SAS program reads the data in the file
and prints the data when the tra~saction date is
equal to January 31, 1986:
EXT.RACTING DATA
A fundamental problem facing
auditors of
computerized financial
systems
is that of
obtaining or extacting the data from the
accounting files. Factors that m'ust be considered
are the type of access method used by the files,
the format of the records in the file, and the
format of the data within each record.
DATA;
INFILE ACCTBAL;
INPUT @1 RECTYPE $2.
@3 MAJACCT $3.
@6 SUBACCT $3. @;
IF RECTYPE='lO' THEN
INPUT @9 TOTLVL $1.
@10 RPTSIGN $1@11 RPTLINE $10.
@21 DESCRIP $40.;
IF RECTYPE='20' THEN
INPUT @9 TRAMT
PD6.
@15 TRNUM
$5.
@20 TRDATE YYMMDD.
@26 TRJOUR $2.
@28 TRDESC $30.;
IF RECTYPE='30' THEN
INPUT @9 HRDATE YYMMDD.
@15 (HRAMTI-HRAMT13) (PD6.);
IF TRDATE='31JAN86'D;
PROC PRINT;
RUN;
Most of the access methods used by files stored
under IBM's MVS operating system can be
handled by exisiting fourth-generation -languages
and audit software packages.
Some example
access methods that might be encounter~d by an
auditor are sequential access (QSAM, SAM,
BSAM),
indexed access
(ISAM,
VSAM),
A library of SAS macros that contain the
SAS INPUT statements to read the files could be
stored and maintained separately from the
auditing programs.
direct
access (DAM, BDAM). If the accounting system
uses data base software, the audit software will
need to have a special interface program in order
to obtain the data in the data base. lMS and
IDMS are two data base systems that are
supported by a few audit software packag,es.
The format of the records in an accounting file
will vary greatly depe'nding on the application.
Several different types 'of records may be needed
for a single application. Most audit software can
handle fixed record layouts j'n fixed o'r variable
length records. Additional programming may be
490
By using previously stored file descriptions, the
amount of the programming the auditor must
know can be greatly reduced. I n addition, an
auditor's time can be saved by having the
programming statements for reading the file
already developed.
This program reads and
prints the data as before but a SAS macro for the
input statements has been used:
TRANSFORMING DATA
Data extracted from a file may not contain all the
information an auditor needs Or the file may be
too large to handle efficiently. Often, the data
that has been extracted must be transformed so
that it is more usable for audit purposes.
Being able to subset a file quickly and easily is a
feature found in most audit software. Records
that an auditor wants to review can be separated
from the file with a subsetting IF statement in
SAS software. Selecting all accounts receivable
balances over a certain amount or the credit
limit, selecting expenses for a department, or
selecting all expense accounts from a trial
balance are some examples of why an auditor may
want to subset a file.
DATA;
%ACCTBALj
IF TRDATE='31JAN86'D;
PROC PRINT;
RUN;
For all records:
COLUMNS
01-02
03-05
06-08
FOmlAT
DESCRIPTION
character
character
character
record type code
major account number
sub account number
Auditors may also be looking for a subset of
accounting data that is not in the file. Missing
check, voucher, or purchase order numbers are
examples where an auditor searches for items
that have been skipped. These source documents
are sequentially numbered and tests can be easily
made to determine if a number has been skipped.
There are cases where the sequence numbers are
really a combination of letters and numbers which
is not as easily checked as a true number. The
SAS program, %SEQCHK, in Appendix II can be
used to test for missing items when the sequence
number is either all numeric or mixed (character
and numeric).
If record type code is '10' then account header:
COLUMNS
09-09
10-10
11-20
21-60
FOR:-IAT
=====
character
character
character
character
DESCRIPTION
===--========
total level code
sign for account
line number for fin. stmts.
account description
If record type code is '20' then monthly transaction:
COLUMNS
09-14
15-19
20-25
26-27
28-57
FORMAT
DESCRIPTION
packed num
character
character
character
character
transaction amount
transaction number
tansaction date (YYMMDD)
journal posted from
transaction description
In addition to searching for missing items, an
auditor may want to find items that have been
duplicated. %DUPCHK is a SAS program that was
created to locate records that occur more than
once in a file. The program is in Appendix II.
Combining data from different files is often
required by auditors. The software being used
must be able to merge several files and match the
records on key fields. Consider a compliance
test that matches pu rchase orders to cash
disbursements or a
program
to
generate
confirmations from accounts- receivable balances
that must be matched to the customer's name and
address file.
Perhaps the best application for
matching files is when data from parallel tests of
computerized accounting systems needs to be
reconciled. SAS software allows for up to fifty
files to be merged at one time. An example SAS
program that merges data from two files is
%RANDSAMP which can be found in Appendix III.
If record type code is '30' then history record:
COLUMNS
09-14
15-92
Figure 1.
FORMAT
DESCRIPTION
character
packed num
date last posted (YYMHDD)
amounts for 13 months
Record Layout for Trial Balance File.
Before records in files can be matched and
merged, the key fields that uniquely identify the
records must be determined. Common key fields
are account numbers, part numbers, purchase
order numbers, and serial numbers.
In order
for the records to be matched, the key fields
must match precisely. Many times the fields do
not match with the precision required by
computers. Here is a true story of one such
situation and how it was resolved with SAS
software.
Using predefined file descriptions is quite
common in data processing. The advantages of
this approach are that the file descriptions can
be maintained
independently of the audit
programs and that the auditor does not need to
be concerned with the physical layout of the file.
Appendix I of this paper outlines. the steps
necessary to use a library of file descriptions
with SAS software.
Moveable equipment within a company was
identified by a number attached to each item.
The id number was used to identify the
491
equipment in three different automated systems
that belonged to three different functional areas
in the company. Each system maintained slightly
different data, but all three maintained the id
number and acquisition cost for each item. Two
problems existed: first, the total costs reported
in one system did not match the others and
secondly, the id number was really a string of
digits in two of the systems.
The day of
reckoning came when the Vice-President of
Systems and Finance wanted to know within
twenty-four hours why there was a ten million
dollar discrepancy in the moveable equipment
figures reported by the various systems.
balance could be complex in most languages.
SAS software stores all dates internally as the
number of days (plus or minus) from January 1,
1960. This means that dates can simply be added
and subtracted as desired within SAS programs.
Several functions can be used to convert nonSAS dates to SAS date values and vice-versa,
Time values are also stored as numbers with
functions to convert them as necessary to
readable forms.
There is one caveat to using SAS to perform
calculations on accounting data.
Numeric data
stored in SAS programs is maintained and used in
calculations at double-precision accuracy (16
decimal places). Since most accounting data is
rounded to one-hundredths of a dollar, the extra
precision that SAS numeric values maintain can
be a problem. All calculations in SAS programs
should use rounded numeric values. The ROUND
function in SAS software is provided to handle
these situations.
The solution was to merge the files and isolate
the few items that made up the difference,
however the files could not be merged because
the id numbers were not consistent. Depending
on the system used, the id numbers might have
one of the following -forms:
standard numeric: 10, 1238, 53861
variable-length string: '10', '1238', '53861'
Ii xed-length stri ng: '000010', '001238', '053861'
Descriptive statistics can be used to obtain some
basic information about the data file being
tested.
Frequency counts, histograms, and
calculations of the mean, standard deviation, or
range are all effective ways to get summary
information accounting data. The UNIVARIATE
procedure in SAS softwar'e is especially useful
for taking a quick look at data.
To use the
UNIVARIATE procedure on a SAS data set, the
following statements could be used:
SAS software was used to transform the 'almost'
precise id numbers to a more precise form that
could be used to match the files. The result was
that all but about $30,000 of the equjpment
ermrs were reconciled when the files were
merged. Here are the SAS statements (in capital
letters) that were used to convert the numbers to
a consistent form:
PROC UNIVARIATE PLOT;
VAR Al·IOU~T;
RUN;
convert 1238 to '001238':
I D"LEFT( PUT (I DNUM, Z6,));
convert '1238' to '001238':
ID"LEFT(PUT( I NPUT( I D,6,), Z6,));
This short program will generate several pieces
of
useful
information
about
the
variable
AMOUNT, An auditor will want to look at the
output for the following:
SAS programmers can use built-in functions to
change data or perform other routine task's that
require several statements in other languages,
Several built-in functions like LEFT, INPUT, and
PUT
are
available
in
SAS
software
for
transforming data,
In addition PROC FORMAT
can be used to recode data as desired according
to lists or ranges of values. The SAS program,
RECODE, in Appendix II is an example of how
PROC FORMAT might be used with accounting
data,
the number of occurrences
the mean, standard deviation, and variance
of the values
the skewness and kurtosis of the distribution
the range and sum of the values
the five lowest and highest values
the quantiles of the values
ANALYZING DATA
a histogram of the values.
Most generalized audit software packages allow
for various tests and calculations to be performed
on accounting data. 8
Descriptive statistics
can be used by auditors to gain an overall view
or 'feel' for the data.
Figur'e 2 is an example of the output from the
UNIVARIATE procedure. For this example, the
auditor can verify:
With SAS software, any type 01 mathematical
calculation can be performed on the data. The
programming required for these calculations can
be extensive or short depending on the task and
the availability of a function to handle the
calculation. For example, subtracting two dates
to determine the age of an accounts receivable
that these 1600 items have a total balance of,
S878,300
that most of the balances (9996) are less than
$2,310
492
that the highest balance is $4,681 and the
lowest is $6
UNIVARIATE
VARIABLEo::MlOUNT
HISTOGRAM
that the distribution is exponential, because
the mean and standard deviation are nearly
equal 9
II
1
2
1
4
5
2
that there are several large values, because
a positive kurtosis indicates that several
values exists in the tails of the distribution 10
BOXPLOT
S
that these large values are positive, because
a positive skewness indicates that more
values exist to the right-side (or positiveside) of the mean 11
14
D
16
••<
12
14
25
o
I
I
I
15
26
41
UNIVARIATE
74
158
VARIABLEo::A:iOUNT
100+,t"i"~'H,;"""**'~i"':"i"d"Hrl""''<i'''"h'''~*i'i'"i,,,,''''''''*,'<,H,,',**,~i'i'"kI.-f"'<
~IO~lEl\TS
N
~EAN
STD DEV
SKEW~ESS
DSS
el'
T:~!EAt.;o::O
SG~
NlJ!-1
RAJ\K
,;
0
1600
548.938
742.987
2.58516
1364826356
135.35
29.353
640400
1600
SUe! \o;'GTS
SD:!
VARIA~CE
KCRTOSIS
ess
STD ~!EA\'
PROB> ITI
PRoB>ISI
QUANTILES(DEFo::4 )
100%
~jAX
75% Q:3
50% l1ED
25% Ql
0% MIN
4681
669
245
115
6
99%
95%
90%
10%
-- - -+- - - -+- - - -+- - --+-- - -+- -- -+- - - -+- - - -+- - - -+- -,Ie
1600
878300
552029
7.1-6937
882694550
18.5747
o 0001
0.0001
LOWEST
1382.7
76
5~
52
9
l':~
20.02
11
+-----+
I + I
272
717
+-----+
*-----*
MAY REPRESENT UP TO 15 COUNTS
Figure 2 (cant.).
Sample Output from PROC UNIVARIATE.
UNIVARIATE
EXTREclES
3591.82
2310.4
154
HIGHEST
4180
4282
4491
4579
4681
VARIABLE=A~toUNT
NORt!AL PROBABILITY PLOT
4700+
I
RA~GE
4675
!
I
Q3-Q1
MODE
554
110
I
I
I
I
I
Figure 2.
Sample Output from PROC GNIVARIATE.
I
I
+
++
I
I
I
i,
I
+++
+++
I
I
I
I
I
I
I
+++
'.'**
I
1 OO+,H""'h·,-,"_"""';',~,~,·,,,·.
+-- - -+- - - -+- - - -+- - •• +. - - -+- - --+_. - -+-~ - -+- - --+_ •• _+
-2
Figure 2 (cant.).
-1
0
+1
+2
Sample Output from PROC UNIVARIATE.
A one-page summary of every account in a trial
balance could be easily generated with the
UNIVARIATE procedure when a BY statement is
added to the program.
The BY statement
indicates that the data should be processed in
groups within the file (e.g. BY ACCOUNT;).
SAS/GRAPH® Software can be also be used to get
a quick idea of how the data looks. Figure 3 is a
vertical bar chart of the same balances that were
493
the costs of doing so are usually prohibitive.
Programs for statistical sampling can be found in
most audit software packages. 12
used for the UNIVARIATE procedure.
The
SAS/GRAPH procedure, GCHART, was used to
create the graph. Once again, only a few SAS
statements are required to produce the output:
Before statistical sampling was widely accepted,
auditors sampled records based on their own
selection criteria. This meant that two auditors
may not select the same records because their
judgement might differ. Statistical sampling is
preferred over non-statistical
sampling for
several reasons:
PROC GCHARTj
VEAR AMOUNT;
RUN;
Two other SAS procedures are useful for the
initial analysis performed on accounting data:
PROC
SUMMARY
and
PROC
FREQ.
The
SUMMARY
procedure can
provide statistics
similar
to
the
UNIVARIATE
procedure.
the sample result is objective and defensible
the sample size may be estimated objectively
in advance
In
addition, PROC SUMMARY can be used to sort
and sum records.
When
BY and
CLASS
statements
are
used
with
the
SUMMARY
procedure, totals or statistics for departments,
districts, regions, or other accounting units can
be generated. The FREQ procedu re can produce
frequency tables on groups of data, although
most accounting data must be receded before this
procedure can be used effectively. Refer to the
RECODE program in Appendix II for an example.
sampling error may be estimated
the results can be as or more accurate than
10096 tests
audit costs can be reduced
field work performed by different auditors
can be evaluated collectively
the evaluation is objective.
FREQUENCY
13
Several different sampling plans are used by
auditors depending on the data that must be
tested.
Arkin's Handbook of Sampling for
Auditing and Accounting covers sampling plans
and sample evaluations in detail and provides
step-by-step
instructions
for
auditors.
Recently, auditors have focused on a sampling
method
that is especially well suited for
accounting data: monetary-unit (or dollar-unit)
sampling. Monetary-unit sampling is described
in detail in Dollar-Unit Sampling: A Practical
Guide for Auditors. A complete discussion of
sampling plans, when to use a specific plan, and
how to evalute the sample results is beyond the
scope of this paper.
SAS software was first developed for statistical
applications. The software has many procedures
and functions to aid writers of statistical
programs,
however auditors
will not find
sampling
programs
readily
available
for
accounting files.
The programs provided in
Appendix III should cover the basic requirements
of statistical sampling for auditing applications.
400
eoo
1200 1600 2000 2400 2eoo 3200 3600 4000 4400
The programs in Appendix III for sampling and
sample evaluation are
AMOUNT MIOPOINT
Figure 3.
%RANDNUM
Sample Output from PROC GCHART.
generates
psuedo-random
numbers
%SAMPSIZE
determines
sample
size for
random sample
°6RANDSAMP - selects an unrestricted random
sample
STATISTICAL SAMPLING
Auditors have relied on tests performed on
samples of accounting data in both manual and
automated auditing.
In many cases, it is
impossible to test every record. Even when it is
theoretically possible to test 100% of the records,
%SYSSAMP - systematic (or interval) sample
selection
%MUSSAMP
selects monetary-unit sample
using cell selection
494
These programs have been implemented as SAS
macros. To use them, the data must be in a SAS
data set. Then, the macros are submitted for
processing
with
the
necessary parameters.
Auditors do not have to know how to program in
SAS to use these prog rams.
A complete
description of each program and examples on
their use are included in Appendix III.
Although some SAS users claim that the
TABULATE procedure is difficult to use, only' a
few SAS statements are required to produce well
formatted reports. Auditors that become familiar
with this procedure will find that summary
reports can be prepared quickly.
lID .... Entertainment,
Saln AnalySiS 10)' state
I'I<lntl>ly Sale&
REPORT WRITING
JAIIUAllY
Base SAS software has several procedures for
reporting that range from simple listings to
tabular reports to reports in the form of a
calendar. The FSCALC procedure, an interactive
spreadsheet in SAS/FSP® software, can also be
used to print reports in either interactive or
batch mode. SAS/ETS® software contains PROC
COMPUTAB which is a report writing procedure
that is well suited for financial data.
And
finally, if none of these procedures can be made
to print the data as desired, the DATA step in
Base SAS software can be used to develop custom
reports.
110 $1,ooOs)
SOle<
Sole<
State
Typ .. of Sale
IlIlnol ..
ca.h
1,1"8
1,32)
7,991
6,995
6,661
Credit
7,133
8.166
7,910
9,125
7,300
14,281
15,489
15.901
16,120
13.961
Cuh
7,720
1,121
9,528
7,906
8,519
C .... dit
7,300
6,361
1,526
6,968
1.199
15.020
1l,486
11,056
14,894
15,118
All Saln
Indians
~entucky
Michigan
'"'
'"'
'"no
."".
Type or Sale
cash
7,420
7,089
7,015
1,28~
6,162
Credit
7,885
7,004
8,492
8,333
7,262
15,305
14,093
15,501
15,616
13,424
Salas
Type or S'le
Credit
'"
."
,,,
Tyl''' or sal8
'"
State.
Figure 4.
Totel
JUNE
FEBRUARY
salas
Summary reports from accounting data will
depend on the format of the data. This means
that it is difficult to supply an auditor with a
library of programs for report writing. Exisiting
audit software packages and fourth-generation
languages have programs that simplify the
programming, but an auditor must still specify
the format of the report. 1-10
Inc.
6,656
7.717
9,206
7,509
6,964
8,263
6,458
6,268
8.286
7,499
14.919
14.175
17.496
15,791
14.463
59,525
51,245
65,960
62,429
57,566
."
2,630
to produce confirmation letters
to print aging schedules
to print mortgage amortization "schedules
for project scheduling to plan the" audit
for trend analysis
15
The SAS System provides procedures to handle
many of these same audit tasks. For instance,
PROC FSLETTER can be used to produce
confirmation letters or dunning letters.
PROC
LP solves linear programming problems. PROC
FORECAST can be used for trend analysis, and
it has options to compensate for seasonality as
well. Project scheduling is performed by PROC
CPM
and
PROC
ASSIGN.
Fixed-rate
loan
amortization schedules are generated with PROC
MORTGAGE.
495
76,954
35,375
39,264
38,230
Example Output from PRoe TABULATE.
to solve linear programming problems.
35,907
no
on
For example, some packages provide programs:
TITLE 'HOME ENTERTAINMENT, INC. ';
PROC TABULATE FORMAT=COHMA9.0
CLASS STATE SALETYPE MONTH;
VAR AMOUNT;
LABEL
AMOUNT=' SALES,'
STATE=' STATE'
SALETYPE=' TYPE OF SALE'
!10]\''TH='~lOKTHLY SALES
(IN $1,0005)';
KEYLABEL
SUM=' A~10C;-';T' ;
TABLES STATEi'(SALETYPE ALL=' ALL SALES') ALL=' ALL STATES' ,
(NONTH ALL= 'TOTAL' )".!IJlOU~T/BOX=' SALES A~ALYSIS BY STATE';
RL"N;
"1,0"7
74,639
Generalized audit software packages usually
contain programs to handle a variety of
miscellaneous audit tasks,
Some of these
programs are specialized and can only be used on
certain types of audits.
Other programs are
provided to handle administrative details for
auditors.
The TABULATE procedure in SAS software is one
of the most powerful reporting procedures
available to an auditor. It works well with files
that have data for several classes or groups
(e. g.
departments,
regions,
branches,
districts). Figure 4 shows a report generated
from the TABULATE procedure.
Here are the
SAS statements used to produce the report:
16,459
'"
OTHER AUDIT TASKS
When reports are prepared with a DATA step
program in SAS software, the program developer
can choose to complete all the fields on a report
page and then print that page.
Refer to the
"Report Writing" section in the "DATA Step
Applications" chapter of the SAS User's Guide:
Basics for an example program that demonstrates
whole-page printing. This is a unique feature
for reporting that is not found in other software.
With this option, directory-style listings or
multi-column reports can be produced.
36,511
39,888
39,071
17.303
305,355
t:
!
Appendix IV has specific details on using PROC
FSLETTER for producing confirmation letters.
The appendix also has program, ~,GPMLOAN,
which can be used to
produce mortgage
amortization schedules for graduated payment
loans.
Audit System PrImary Menu
Command ===>
press END to Return.
Option
Description
==""''''='''='''====================~==='''='''=============''''''=====
Setup default parameters and JeL
Browse SAS data set Or SAS pr09ram statements
Edit SAS data set or SAS pr09ram statements
Utility Functions: allocate data sets, delete data sets
Extract data from files or create ne'>l data sets
Audit program library·~ samp1in9 programs
Report writing facility
Audit confirmation letter.s
Although this paper does not specifically cover
the audit tasks related to auditing the EDP
function within a company, a program is provided
in Appendix IV which will produce a crossreference listing of program names and the files
used in the programs. The report also keeps
track of the programs and files that are used in
cataloged job control language procedures. EDP
auditors and maintenance programmers will find
this a useful program.
Financial
systems
auditors may need it to find all the programs or
jobs that modify a file.
Refer to <tXREF in
Appendix IV for the details on using this
program.
o
T
S
X
Go to SAS Display Manager System
Tutorial on the Audit System
Go to IS?F/POF (SPF/POF) .~ if available
Exit
Figure 5.
Sample SAS/AF Menu.
A COMPLETE SYSTEM FOR AUDITORS
Most generalized audit software packages on the
market today were developed in the 1970s or
earlier. During that time, computer programs
were usually run in batch mode. Some of the
audit programs require auditors to prepare
control statements in a fixed format. Interactive
auditing programs were available from timesharing companies.
Enter an option nUmber/letter on the I ine above.
Extract data from a non~SAS fi Ie
Command ===>
Extract from fi Ie:
Data
II:saspl "~'==============
Model Set
DataName
Set ===>
=="'> &model_
Create SAS Data Set:
~~~a w~~~ r~ r~ r:~~e ~~~~
Data Set Name
:sa sd I Ib' _ _,(",.~,~."~'~'T'
"'==> &sasdset
'0;;;'"-"",.,,~.,,,.;;;,r;,--
If the nQ'l~SAS fi Ie has been prevlol,lsly used by thi5 sY5tem, the
field definitions used last wi II be displayed,
Use a ? for Data Set
Name of extract file to view list of previously used extract files.
Computing in the 1980s has been characterized
by wide-spread user access to computers via
terminals or microcomputers. Systems have been
created to obtain information from the user and
then the system performs the necessary tasks to
satisfy a user's re-quest. With these systems,
people with little or no understanding of
programming can use computers effectively in
their jobs.
Jump to Opt i on ===> lI:optnum
Press PF3/PF15 Or enter END on
The SAS System can be used to develop
interactive systems for a wide variety purposes
including to assist auditors with obtaining
accounting data from machine readable files and
performing audit tests on that data. SAS/AFH~
software can be used to create a generalized
auditing system that uses menus and fill-in-theblank screens. Figures 5 and 6 show what an
interactive system might look like. Figure 5 is
the primary menu from which an auditor would
select a task. Figure 6 shows the screens that
could be used to extract data from a non-SAS file
for process'ing.
Figure 6.
co~mand
'I ine to continue.
Sample SAS/AF Fill-in-the-Blank Screen.
Fi II in the variable InfOrmatiOn below for each data field you want
to read off the records In the fi Ie.
Press PFll/PF23
Press PF'10/Pf22
Press PF3/Pf15
the information
Name
The SAS System can also be used with
microcomputers to provide an efficient alternative
to mainframe processing.
An auditor could
extract data fro.m accounting files on a mainframe
and then download these files to a microcomputer
for processing.
Internal auditors or Certified
Public Accountants that audit several locations
may find this approach useful since data can be
collected in the field and then brought to the
office processing.
or enter RIGHT on command I ine to view next s.creen.
or enter LEFT on command I ine to return to previous screen.
or eneer ErfD
on command I ine when finished with
required.
--InpUt Data fleld~~
Start Informat
Label
Format
Figure 6 (cont.) Sample SAS/AF Fill-in-the-Blank Screen.
496
13. Herbert Arkin, Handb,ook of Sampling for
Auditing
and
Accounting
(New
York:
McGraw-Hili Book Company, 1984), pp. 9-12.
SUMMARY
The computer and generalized audit software
provide the auditor with the tools necessary to
perform reliable, efficient, and cost-effective
tests on computerized financial data.
14. Institute of Internal Auditors,
How to
Acquire and Use Generalized Audit Software,
pp. 53-55.
SAS software has the features needed for most
auditing applications, but an' auditor is required
15. Ibid.
to spend too much time writing programs to use
these features. The library of auditing programs
included with this paper help to move SAS
software closer to becoming an
acceptable
generalized audit software package that does not
require
an
auditor
to
have
significant
programming skills.
BIBLIOGRAPHY
Adams, Donald L. and Mullarkey, John F. "A
Survey of Audit Software." The Journal of
Accountancy (September, 1972), p. 39:
A rki n,
Herbert.
Handbook of Sampling for
Auditing and Accounting. New York: McGraw-Hili
Book Company, 1984.
FOOTNOTES
1. Howard F. Stettler, Auditing Principles
(Englewood Cliffs, N.J.: Prentice-Hall, Inc.,
1977), p. 522.
Davis, Gordon B.; Adams, Donald L.; and
Schaller, Carol A. Auditing and EDP. New York:
American
Institute
of
Certified
Public
Accountants, 1983.
2. Gordon B. Davis, Donald L. Adams, and
Carol A. Schaller, Auditing and EDP (New
York: American Institute of Certified Public
Accountants, 1983), pp. 3-4.
Hill, Henry P.; Roth, Joseph L.; and Arkin,
Herbert.
Sampling in Auditing': A Simplified
Guide and Statistical Tables. Huntington, N.Y.:
Robert E. Krieger Publishing Company, 1962.
3. Institute of Internal Auditors,
How to
Acquire and Use Generalized Audit Software
(Altamonte Springs, Florida: Institute of
Internal Auditors, 1979), pp. 53-55.
Institute of Internal Auditors. How to Acquire
and Use Generalized Audit Software. Altamonte
Springs, Florida: Institute of Internal Auditors,
1979.
4. Ibid.
Leslie, Donald A.;
Anderson, Rodney
Practical Guide for
Copp Clark Pitman,
5. R. K. Mautz and Hussein A. Sharaf, The
Philosophy of Auditing p. 86, quoted in
Donald L. Adams and John F. Mullarkey, "A
Survey of Audit Software", The Journal of
Accountancy (September, 1972), p. 39.
Teitlebaum, Albert D.; and
J. Dollar-unit Sampling: A
Auditors. Toronto, Canada:
1979.
6. Ibid., p. 40.
SAS Institute Inc. SAS Users Guide: Basics.
Version 5 Edition. Cary, N.C.: SAS Institute
Inc., 1985.
7. Gordon B. Davis, Donald L. Adams, and
Carol A. Schaller, Auditing and EDP, pp.
395-400.
SAS Institute Inc. SAS/AF Users Guide. Version
5 Edition. Cary, N.C.: SAS Institute Inc., 1985.
8. I nstitute of Internal Auditors,
How to
Acquire and Use Generalized Audit Software,
pp. 53-55.
SAS
Institute Inc.
SAS/FSP Users Guide.
Version 5 Edition. Cary, N.C.: SAS Institute
Inc., 1985.
9. Maurice S. Newman, Financial Accounting
Estimates Through Statistical Sampling by
Computer (New York: John Wiley and Sons,
1976), p. 54.
SAS Institute Inc. SAS Views: Processing. 1983
Edition. Cary, N.C.: SAS Institute Inc., 1984.
Steele, Robert G. D. and Brocklebank, John C.
Introduction to Statistics Using the SAS System.
Statistics Lecture Series. Ca ry, N. C.: SAS
Institute Inc., 1984.
10. Robert
G.
D.
Steel
and
John
C.
B rockleban k, I ntroduction to Statistics Using
the SAS System, Statistics Lecture Series
(Cary, N.C.: SAS Institute Inc., 1984), pp.
115-118.
Stettler,
Englewood
1977.
Howard
Cliffs,
Auditing
Principles.
F.
Inc.,
N.J. : Prentice-Hall,
of
Internal
Wallace,
Wanda
A.
Handbook
Accounting Controls. Englewood Cliffs, N.J.:
Prentice-Hall, Inc., 1984.
11. Ibid.
12. Institute of I nternal Auditors,
How to
Acquire and Use Generalized Audit Software,
pp. 53-55.
Wilburn, Arthur J. Practical Statistical Sampling
for Auditors. New York: Marcel Dekker, Inc.,
1984.
497
APPENDIX I.
Descriptions
Using
SAS
Macros
for
File
APPENDIX II.
It is recommended that file descriptions for nonSAS
files
be maintained
in
SAS macros
independent of the programs that use these file
descriptions. By doing so, an auditor can save
time by not having to code the file description
for each program. Also, the auditor will not have
to learn how to write programs for complex file
structures.
%SEQCH K Macro
~AGRO
SEQGHK
(I!.;'=_LAST_,OUT=_Nt:LL_,VAR=. ,PATTERN=.);
.
I'H""**'''''*''''''*"**'''~''''"I'''''''"I''''''''''''''''''''-{''''"riI;'''''H''''',,;,'':';dn",.;":"",*"',"I" ,"I.-I,·;,"I....·";·'H""'",-:.'.,,,,,~,~, /
1*'":* Sequence Checking Macro - will verify that a sequence
*"..,,'/
1'>*",
'number' has not been skipped. The 'number' maY'be
,."."",/
1M"",
a string of numbers, a string of digits and letters, ,H",/
1*";'
or a string of letters. If the sequence number is
m"",/
1*'"''
a numeric variable, a simple data step that adds one ''''''''''/
IM'~'
The macros should be stored in a central library
that can be shared by all users.
The macro
library should be a partitioned data set where
each member name is the same as the macro name.
To make this library available to SAS users, the
new AUTOCALL library option is recommended.
Here is how the library is allocated to a SAS
program:
I''';'''
I,H,,",
to the number will be more efficient than this macro. ;,..,,"1
I:.;PUT,
1**'"
1***
'''''*1
SAS data set that has been sorted. If it is
has not been sorted, the program will stop
after 10 out-of-sequence errors have been met.
I*"i."""i:
I,"rlr{/
Ot. . TPl.:T:
I,rm',
Either a SAS data set or a printed report of
the items that have been skipped .
1''**
I''''':'';'
I**"
USAGE:
1**"
I,"',H,
I,,,H,
in TSO: SAS AUTOS('''your.library.name''')
with batch JCL:
II EXEC SAS,AUTOS=·your.library.name'
%SEQCHK(IN=,
OUT=,
VAR=,
PATTERN=) j
where
1"**
1;''''*
I*'~"
1"*'"
1''''''*
Recall from the Extracting Data section of this
paper the example that used a macro for the file
description. Here is that program again:
I'"''''
/**,.
/*,,,,,,
1*>'*
1;'*"
DATA;
90 ACCTBAL
"'**1
**""/
-{'**I
-{,**/
***1
*;""/
%SEQCHK( IN=SEQDATA,
OUT=SEQERR,
VAR=PARTItm
PATTERN='CGSNN') j
SAS Institute Inc.
**'~I
%IF &VAR = . OR &PATTERN = . %THEN %DOj
%PUT %STR(ERROR: 'VARIABLES WITH MISSING VALUES ARE REQUIRED) j
%PUT %STR(ERROR: VAR--&VAR
PATTERN=£PATTERN);
%GOTO M-EXITj
%ENDj
%1£T STRLEN=%LENGTH(&PATTERN) j
%LET STRLEN="'"zVAL(&STRLEN - 2)
021 DESeRTP $40.;
IF RECTYPE~120r THEN
INPeT @9 TRA~IT
@15 TRNU~l
C!20 TRDATE
(c26 TRJOIJR
TROESe
IF RECTYPE~13Q' THEK
~28
RETAI~ CSTR~C
PD6.
$5.
'ABCDEFGHIJKU1~OPQRSTUWXYZ';
RETAI~ GSTICSL '0123456789ABCDEFGHIJKL1-lNOPQRSTUVWXYZ'
RETAr:.; CSTR_NH 'ABCDEFGHIJKLl'lNOPQRSTUVWXYZ0123456789'
RETAIN CS1"R-N '0123456789';
RETAIN SEQC:-''T 0;
LENGTH. PAT_GRR STILGRR S 1;
LENGTH 1-lSG $ 25;
KEEP MSG &VARj
YY:·j~lDD.
52.
530.;
INPUT @9 HRDATE YYMNDD.
@15 (HRAMTl- HRAMTl3) (PD6.);
ACCTBAL;
The statements in the
the program wherever
Note that this macro
DDN= to be specified
example the parameter
default value for DON,
j
DATA &OUTj
LENGTH PATTERN PREVIOUS CURRENT $ &STRLEN j
RETAIN PATTER:-i &PATTERN;
RETAIN PREVIOCS &PATTER!';
@11 RPTLINE SID.
I
SAS data set for input, if
*'"'*1
ommitted then _LAST_ used.
***1
OUT=
SAS data set for output (opt) . *'''*/
VAR=
name of variable to be checked . ***/
PATTERN= quoted string in which
***/
represents collating sequence: ,",**/
N:cnumer ic only
*",,* /
L=numbers then characters
,-ro,,:/
H=characters then numbers
*'>*1
G=characters only
***1
S=skip or special character·***1
would be coded as follows:
%MACRO ACCTBAL(DDN=ACCTBAL);
INFILE &DDN;
INPUT @1 RECTYPE $2.
@3 MAJACCT $3.
@6 SUBACCT $3. @;
IF RECTYPE='lO' THEN
INPUT @9 TOTLVL $1.
@10 RPTSIGN $1.
~~NEND
,.**/
*""*1
*>,*/
***1
,,**/
,,:-:.,,,/
***/
***/
**"1'1
**""1
-/
I"''''';' EXAl'lPLE:
1*'":-,":
1''''"'*
1'''"'*
1**""
/,"'*""
I"""'"
RUN;
'-";<>"1
IN=
I~'*'":
%ACCTBAL;
IF TRDATE='31JAN86'Dj
PROC PRINT;
*"''''/
*'",-{'I
/-*
1'>**
The macro
SAS Programs for Checking and
Transforming Data
SET &INj
GURRENT=UPGASE (&VAR) ;
IF _1'_ = 1 THEN DO;
PATIERN=REVERSE (UPGASE (PATTERN» j
pREVIOUS=CURRENT;
RETURN;
END;
macro are substituted in
the macro name is used.
allows for a parameter,
when it is used. J n the
was not specified so the
ACCTBAL, was used.
IF CURRENT=PREVIOUS THEN DO;
MSG='*** DUPLICATE ITEM ,~,"'*';
&VAR=CURRENTj
LINK PRTOUT;
REruRNj
El\1};
498
j
j
NEXLSEQ:
1**'1,
COME HERE TO SEE IF NEXT NUMBER IS MISSING
'**'''1
IF CURRENT<PREVIOUS THEN DO;
~lSG='*"'* OUT OF SEQUENCE -.<**';
SEQCNT+l;
&VAR=CURRENT;
LINK PRTOUT;
IF SEQCI\T > 10 THEN DO;
FILE LOG;
PUT 'ERROR: 10 RECORDS WERE OUT OF SEQUENCE';
PUT 'ERROR: ',,"''riri. PROGRAM TERMINATED 'I,*,,:*-{,'
STOP;
END"REnrRN;
END;
1*'':* BUILD NEXT ITEM IN SEQUE!\CE FROM PREVIOUS ,.,.:,,"1
LP=LENGTH(PREVIOUS) ;
PREVIQUS=REVERSE(PREVIOUS) ;
CARRY=l; 1=0;
DO "'HILE (CARRY);
I+l ;
{tit>':
IF PAT_CHR = 'L' THEN DO;
VALU '" INDEX(CSTILNL,STR_CHR) + 1;
IF VALU<2 THEN DO;
MS8='*'''* INVALID DATA *-Irli';
&VAR=PREVIOUS;
LINK PRTOUT;
PREVIOUS=CURRENT;
RETURN;
END;
IF VALU<37 THEN DO;
SUBSTR(PREVIOUS, I, l)'"'SUBSTR(CSTILNL, VALU, 1);
CARRY=Q;
GOTO END_LOOP;
END;
IF VALU>36 THEN DO; 1*** PREPARE TO CARRY ***1
VALU=VALU-36;
SUBSTR(PREVIOUS, I, 1)=SUBSTR{CSTR_NL, VALU, 1);
CARRY'"'I;
GOTO END_LOOP;
END;
Et-.'D;
li<>':* liSE CHAR LOW-NUM HIGH COLLATE SEQ1,*"'1
IF PAT_CHR = 'H' THEN DO;
VALU = INDEX(CSTR_NH,STR_CHR) + 1;
IF VALU<2 THEN DO;
MSG='*** INVALID DATA *i,*';
&VAR=PREVIOUS;
LINK PRTOUT;
PREVIOUS=CURREI\T;
RETURN;
IF I>LP THEi\' DO;
PREVIQL"S=REVERSE (PREVIOUS) ;
FILE LOG;
PCT 'ERROR: {ti::'OVERFLOW'l'··~i" _1\_= CURRE\'T= PREVIOUS=;
STOP;
END;
1'-""<>'< GET PATIERN FOR CHARACTER
1*1,," USE NUM LOW-CHAR HIGH COLLATE SEQ***/
I
E~D;
PAT_CHR=SUBSTR(PATTERN, 1,1);
IF VALU<37 THEl-i DO;
SL'BSTR(PREVIOUS, I, 1)=SUBSTR(CSTR..NH, VAW, 1);
CARRY=O;
GOTO END_LOOP;
END;
IF VALC'>36 THE~ DO; /"".,<: PREPARE TO CARRY ,,:<,'1'1
VALL'=VALL'-36 .
SUBSTR(PREVIOUS, I, 1 )=SL'BSTR(CSTR..NH, VALl:, 1);
CARRY"'l ;
GOTO END_LOOP;
El\D;
END;
1**'': SPECIAL OR SKIP CHARACTER *'1"':1
IF PAT_CHR :::; 's' THEN. DO;
GOTO END_LOOP;
END;
I'~i,* GET CHARACTER FROM ITEM
,,<*i< I
STLCHR=SUBSTR(PREVIOUS, 1,1) ;
I'''''': USE CHARACTER COLLATE SEQ '1"'",:/
IF PAT_CHR :::; 'c' THEN DO;
VAW", INDEX(CSTLC,STR..CHR) + 1;
IF VALU<2 THEN DO;
)1S8='*""" II\VALID DATA *,':>'r'.
&VAR=PREVIOUS;
,
LINK PRTOUT;
PREVIOUS",CURRWT;
RETURN;
END;
IF VALU<27 THEN DO;
SGBSTR(PREVIOUS, I ,1)=SUBSTR(CSTR_C, VALU, 1);
CARRY=O;
•
GOTO END_LOOP;
END;
IF VALU>26 THEN DO; I'"'''' PREPARE TO CARRY *-"1
VALl'=VALU-26 ;
SUBSTR(PREVIOUS, I, 1)=SUBSTR(C,STR_C, VAW, 1) ;
CARRY=1 ;
GOTO END_LOOP;
END;
END;
END_LOOP:
END;
PREVIQuS=REVERSE (PREVIOUS) ;
IF CURRENT=PREVIOUS THEN RETURN;
IF CURREKT>PREVIOUS THEN DO;
MSG='-:'** ITEM MISSING *>"ri";
&VAR=PREVIQUS;
LINK PRTOUT;
END;
PRTOUT:
I''''''~
PRINT RESULTS OR OUTPUT TO DATA SET
***1
/,'ri"" PRINT RESULTS
*i,* I
%IF &OUT = _NULL.. ~~THEN
FILE LOG;
PUT @9 ~ISG @39 &VAR;
".END;
/'''** USE NUMERIC COLLATE SEQ *,"*/
IF PAT_CHR '" 'N' THEN DO;
VALU '" INDEX(CSTR_N,STR_CHR) + 1;
IF VALlJ<2 THEN DO;
MSG=' ,"''ri, INVALID DATA ,,:,':*';
&VAR=PREVIOUS;
LINK PRTOUT'
PREVIOUS=CURRENT;
RETURN;
EJ>.:D;
IF VALU<l1 THEK DO;
SUBSTR(PREVIOUS ,I, l)<:SUBSTR(CSTR..N; VAW, 1);
CARRY=O;
GOTO END_LOOP;
END;
IF VALU>lO THEN DO; /,·"h': PREPARE'TO CARRY '~>'<*I
VALU'"'VALU-I0;
SUBSTR(PREVIOUS, I, l)=SUBSTR(CSTR_N, VALU, 1);
CARRY=l;
GOTO END_LOOP;
END;
END;
%ELSE %DO;
&VAR=PREVIOUS;
OUTPUT;
%END;
RETURN;
RUN;
%M_EXIT:
%MEND SEQCHK;
499
~~DO;
1*'''* WRITE RESULTS TO DATA SE1'*** I
,
~.
I
Test Program for %SEQCHK Macro
%DUPCHK Macro
1**~~'~********'I,*********~*1,*******,""",*,;-i'*''ri'*',,****irl,****'': /
I**" Test Program for Sequence Check Macro
1***
Itt'......
%MACRO OUPCHK
SAS Ins'titute Inc.
1"h~1
/'h':*****,,':**"~"""':*'iri'~"Wrlt'h'rlr..'''''1'1,***'rirlt'h,,**'·'****,,:*,,:'iri'''''':*,':*,':'Irld,o/rl",':,"",':-{r.H,
I
I'~'~*
variables may be checked. All other variables are
simply output to the new data set.
I*i'~'
If""*
DATA SEQDATA j
INPUT @l PARTNUH $5.
If,of,;,
AA-Sil
I,h";'
I~PUT:
,~** 1
OL'TPCT:
/,",,".*
I*'''~'
AA-96
AA-94
AA-98
AB-13
AB-14
1"1"....'
VSAGE:
1*''<"
I;;·'~*
1***
I*~"~
RUN;
1*"'*
1*"""
I*'~*
~SEQCHK(IN=SEQDATA, VAR=PARTNU~I, PAITER!>;:' CCSNN ')
I**":;
1***
li'** EXA.'1PLE:
;
Sample Output from %SEQCHK Macro
1**'''**''driri:**",*'iriri''Wrl'',,********'i.-<rI.:*>''*''''~'I'<fri''''',*,':**,h'''hh'rl:****;ri'f""'''***'':*1
1<>'0,/
Test Program for Sequence Check Macro
If,,·,*
""'ric /
/*,'0':
*~,* I
***1
*r.I'l
where IN=
SAS data set for input, if
*,w'l
ommitted then _LAST~ used.
'''''*!
OU1'==
SAS data set for output (opt). -{'**I
VARLST= name of variable or variables ***1
to be checked, Separate each ***!
variable name with a space.
***!
Up to 10 names may be used.
***1
"'** /
SAS Institute Inc. ,b",'1'1
%J)tJPCHK(IN=DlJPDATA,
OU1'==OUPERR,
VARLST=ACCOUNT TRDATE AMOUNT);
%IF &VARLST "" . %THEN ~;.oO;
%PUT %STR(ERROR: VARIABLE NAt1E(S) ARE REQUIRED);
%GOTO rLEXIT;
%END;
I*,':***,'rlrl"':**'h':*,',{d'·."**,':**"i.-;"hh'rlt,b"''",;*,h',**,,:*,w,,·,,,**,,*:<,'"':irn,':,hhh',,"***,,,':i, I
1*"* INITIALIZE MACRO VARIABLES "1.-'-""1
%LET VNAl-!ES~UPCASE(&VARLST);
%DO 1=1 %TO 10;
%LET VAR&I=$t1ISSING~;
%ENO;
":OLET VARCNT=O;
259 DATA SEQDATA;
260
INPUT @1 PART:\ml ,s5.;
261 CARDS;
NOTE: DATA SET II"ORK.SEQOATA HAS 10 OBSERVATIONS A~O 1 VARIABLES.
NOTE:
OAT" STATEl'lEST USED 0 . .50 SECOXDS AND 8401::.
THE CmlPILE
PHASE (SED 0.47 SECm-mS.
THE EXECUTION PHASE USED 0.04 SECONDS.
nu:
1"'*" EXTRACT VARIABLE
NA~!ES FROH ~ACRO VARIABLE VAR O{,.,·,"I'I
1=1 %TO 10;
%LET VAR&I=%SCAN(&VARLS! ,&1, t t);
'XoIF &&VAR&I ;; ,sMISSING$ OR &&VAR&I '" %THEN %GOTO EXITJlO;
%LET VARCN!=%EVAL(&VARCNT + -1);
lEND;
~O
272
273 RUN;
274
DUPLICATE ITEM -!rim
AA-91
ITEM MISSING ,~**
AA-93
ITEM MISSING ,,**
AA-94
,W:-,~ ITEM MISSING ,',{rl;
AA-95
OUT
OF
SEQUENCE
***
AA-94
***
~* ITEM MISSING *~,
AA-97
AA-99
*** ITEM MISSING **1,
AB-OO
MISSING
***
ITE"
*'~* ITEM MISSING ,........,.
AB-Ol
ITEM MISSING ,~**
AB-02
ITEM MISSING 'h,,*
AB-03
,"ri"~ ITEM MISSING ,'**
AB-04
,WI/,', ITEM MISSING ,'rlrl;
AB-05
ITEM MISSING ,'rlrl;
AB-06
ITEM MISSING **'~
AB-07
*'~* ITEM MISSING *r.I,
AB-08
*,~* ITEM MISSING *,"t1~
AB-09
**,~ ITEM }JISSING ,~**
AB-I0
"I;U'~ ITEH MISSING ,hW,
AB-ll
**'~ ITE!'! }JISSING ,"**
AB-12
NOTE: THE DATA STATE~IENT USED 0.54 SECONDS AND 972K.
THE COMPILE
PHASE USED 0.48 SECONDS.
THE EXECl.'TION PHASE USED 0.06 SECONDS.
*'~*
%EXILOO:
/,h'''~
PROC
I,"rl:,': Pl.'T LENGTH AND TYPE FOR EACH VARIABLE ''rlt'~1
DATA _NULL.....
SET DUPCHKC;
LE;>';GTH VNA:·IES S 100;
tI
V:\A~!ES '" UPCASE(tI&VARLST );
IF INDEX(V:\~lES,TRHI(NA:IE)) THE~ DO;
DO 1=1 TO 10;
IF TRH!(SCAN(V~Al-lEStItt ')) = TRH!(NA~IE) THEN DO;
HVNAHE='VLEK'IITRlH(LEFT(PUT(I,30)));
CALL SYrlPl.:T (nVNAl'IE , LENGTH) ;
rlVNAME=' VTYP ' IITRH!(LEFT,CPL'T(I,3 0)));
CALL SYMPUT(~1VNA..'1E, TYPE);
END;
END;
END;
~,.
_.,
-
~.SEQCHK(IN=SEQDATA,
GET INFO ON VARIABLES 'h~*!
CONTE~TS DATA=&IN OUT=DVPCHKC MEHTYPE=DATA NOPRINT;
RUN;
***
275
~~DUPCHK(IS=,
,':M'I
""""1
,·,;n"1
''''''*1
***!
*,',,~ I
I*",m
*"'*1
1***
***!
1**'"
*"'*1
I**'t
SAS Institute Inc. ***1
1**'~"Irk'"n."'~of<'''''"i'''rlri'''r*"**,·,****'~***_''"n.w,***,",**,,,**,,,***',,*'h''**'''*******"1,* I
I*'~*
/"..,**
A SAS data set of the items that have been
duplicated.
OUT=,
VARLST:::);
l"i"'''~
AD-IS
1
""w'l
A SAS data set that has been sorted.
I*'~o{'
AA-92
'~**I
'-'**1
,':o{,,~
IM,*
j
CARDS;
AA-90
AA-91
253
254
255
256
257
258
(IN=_LASL. OUT=DUPCHKO, VARLST=. ) ;
1*'~*'~,~***,":'"I,*,w,*,w"",,,,"',,*'h,,*'''**'''',,*~'*"I,*,'''~f''~"I'f'''"I'''!"....·,.:,,·"'.-!:,h"**"I,~,..>,....":'"I"hh..·"~'~ 1
1"*" Duplicates Check tlacro - lOill check to see if a variable ,',*"1'1
l"i"h>
or group of variables has been duplicated. Vp to 10 ,>"IIo{'1
,,:-:,,,:/
*'1'*1
RUN;
/,...,;, NOW CREATE DATA STEP TO CHECK FOR DUPLICATES
DATA &OUT;
REC_NUM+l;
IF REC_NUM > TOLREC THEN STOP;
SET &IN NOBS=TOTJEC POINT=REC_NUt!;
VAR=PARTNilll,PATTERN='CCSNN');
**,'/
!**,~ CREATE VARS TO HOLD LAST VALUES TESTED -{n"*1
LENGTH
%DO 1=1 %TO &VARCNTj
%IF &&VTYP&I ;; 1 %THEN ?~DO;
OC_HLD&I &&VLEN&I
%END;
%IF &&VTYP&I = 2 ;;,THE~ °;00;
OCHLD&I $ &&VLEN&I
%END;
%END;
1*** END OF LENGTH STATEMENT ***1
500
RECODE Program
I.Wd. RETAIN. k'W DROP TE:IPORARY VARIABLES ***1
RETAIN
~~DO 1=1 "oTO &VARCNT;
DC_HLD&I
%ENDj
/**''' END OF RETAIN STATEMENT ***1
DROP
%DO 1=1 %TO &VARCNT;
DC_HLD&I
%END;
1'~'Iri: E~D OF DROP STATE~IE~T "'''''''1
This short program demonstrates how to use
PROC FORMAT to group data or stratify data.
The FORMAT procedure can be used to recode
any type of data. Recoding data can also be
thought of as a table look-Up function. In this
example, a frequency table was produced based
on the groups specified in the format.
1*,',1. FIRST RECORD SET~UP M''''I
IF REC_NL11=1 THEN DO;
LINK SAVLRTN;
RETURN;
PROC FORHAT;
E~D;
VALUE GROUPF
Lov,r-100
101-200
201-300
301-400
401-500
/'"'"" IF STATE~IE:-;'T FOR Cm!PARE -:"""1
IF DC_HLDl = SoI/ARl
'~DO 1=2 o~TO &VARC"l;
AND DC_HLD&I '" &&VAR&I
~EmJ;
THEt-; DO;
/""'" DUPLICATE RECORDS FOUND
REC_NUM=REC_NUM-1 ;
SET &IN NOBS=TOLREC POINT=REC_NUMi
OUTPUT;
REC_NUM=REC_NUM+1 ;
SET &IN NOBS=TO'LREC POINT=REC-,"IUMi
OUTPUT;
END;
I'"''''
SAVE VARIABLES BEH:G CHECKED
SAVE_RTN;
%DO 1'=1 %TO &VARC/>O'T;
DC_HLD&I '" &&VAR&I;
**"1
='<=
100'
='101~200'
='201-300'
='301-400'
='401-500'
SOl-HIGH='SOl
=>';
DATA NUMBERS;
DO 1=1 TO 1000;
MIOUNT=ROUND( (UNIFORH(0)"600) ,1);
OUTPUT;
END;
RUN;
-:"""1
PROC FREQ;
TABLES AMOUNT / LIST;
%E~Di
FaRHAT AMOUNT GROUPF.;
RUN.
RETURN;
RUN;
%~EXIT:
%MEND DUPCHK i
RECODE Program Output
Test PRogram for %DUPCHK Macro
CUMULATIVE
1'/ri'****,·""'<'{"'***i'***"****'~***,,,**,b'rlri'1,***-:.-m"i''''*"I''''H.-I..,'iri..~*'',****,*,'**",., I
1"** Test Program for Macro that Checks for Duplicates
*,,,"1
1***
'h~"I'1
I''<'{'*
SAS Institute Inc. """I
1-I,**,d"~"1'":<i,**,""'";-M,**,·",'"d''''' ,**""",';,-{,-I,****o{",,.,,,+<-<,,'rl:',,",-{p""'*"""''**'''''/ri,**',* 1
DATA DUPDATAi
INPUT @1 ACCOUNT $6.
yy:·It-IDD.
@7 TRDATE
~~ 13 It\'VNU>1
5\ .
@18 It\"VA'IT
7.2
@25 NOTES
$20. ;
CARDS;
RECORD
111111860121L190 11510
111222860121L19021520
RECORO
111333860121L19031530
RECORO
111333860121L19031530
RECORD
111444860121L19041540
RECORD
111555860121L19051550
RECORD
111666860121L19061560
RECORD
111666860121L19061560
RECORD
1
2
3
3 DUPLICATE
4
5
6
6 DUPLICATE
RUN;
%DUPCHK( IN=OUPOATA, OUT=DUPFILE, VARLST=ACCOUNT TRDATE INVNUM);
PROC PRINT; RUN;
Sample Output from %DUPCHK Macro
OBS
3.
ACCOUNT
TRDATE
INV"'UM
INVAMT
111333
111333
111666
111666
9517
9517
9517
95li
L1903
L1903
L1906
L1'.106
15.3
15.3
15.6
15.6
NOTES
RECORD
RECORD 3 DUPLICATE
RECORD 6
RECORD 6 DUPLICATE
501
A~OVST
<=
100
101-200
201-300
301-400
401-500
501
FREQUE~CY
162
161
179
156
164
178
PERCE~T
16.2
16.1
1i .9
15.6
16.4
17.8
FREQUE~CY
162
323
502
658
822
1000
CUMULATIVE
PERCEr..'T
16.2
32,3
50.2
65.8
82.2
100.0
RECODE1 Program
APPENDIX III. Sampling Programs
This example is similar to the previous example
except that- the PUT function was used to create
a new variable, GROUP, in the data set. The
%RANDNUM Macro
%MACRO RANDNUM (OuT"'RANDNl::1, START"'l, STOP"'. ,:-';(J~lBER=. ,SEED"'O,
VAR=RANDNtN, REPLACE"'SO. Fr..:NCTION",r.;:\IFOR~!) ;
output has been printed with PROC TABULATE.
..;,,'**,'''.,'"-,.",."",,,,:,'d"''';,,'''·'''·''*·;'''''';'';''''''''''>i,,'' ,,",'<>'''''*1
tl,-/"·,**'"""~i"'''''*,·,,.,''''·'id,,'',''''·,,,,'·:,,·,*,·,-:
I"'i'''' Random Number
FROG FORt-jAT;
VALUE GROUPF
LOW-IOO ='<=
~lacro - will generate 11 list of random
(normal) numbers. Optional parameters are alloo.ed
for start. and stop so that a range may be specified.
;-;..""
/,."... ,-,
/,'"",-,
100'
i""......
It\Pl'T:
/"",',
OUTPUT:
1*''''
Pi"""",
101-200 ='101-200'
201-300 ='201-300'
301-400 ='301-400'
401-500 ='401-500'
SOl-HIGH='SOl =>';
I''rlr>',
USAGE:
I~
i"""*
I"i".,
DATA NUHBERS;
DO 1=1 TO 1000;
(-I"'''~
(-I""'''
AMmJNT=RDUND( (UNIFORMeD )"<600) , 1) ;
GROUP=PUT(MIOUNT ,GROUPF.);
OliTPUT;
I-I"b'<
1*';'*
1-/,*-1,
END;
SAS data set containing the numbers.
*>""1
where
I'h~*
l,hH,
1''**
1"**
1**-;'
AMOU~~ eN=' COUNT' "';F=6. 0
SUM>'·F=COMMAIO.
I*"~""
r"';'"
MEAN=' AVERAGE AMOUNT 1-·~F=COMHAI0. 2
5TD=' STANDARD DEVIATION''''''F=COMMAIO. 2);
RUN;
1-;'-1<"1,
(-I""""
1,·,-1"'..
Ii"".
ji""o,
ji"''''''
ji"'"''
/'"."
/,,,<,,,
1""':",
Ii"""
RECODE1 Program Output
I
1***
1***
/*** EXAMPLE:
I
A~-lOUNT
1- ----- --- ---------------- ----------- ---I
1
1601
24,6431
154.021
I
1861
46,8091
251.661
1631
74,3121
450.381
'~'~*I
SAS Institute Inc.
%IF &NUMBER =
OR &STOP '"
%THEN ~WO;
%PUT ';;.STR(ERROR: VARIABLES \OlITH ~!ISSING VALUES ARE REQUIRED);
%PUT %STR(
NUHBER=&'NU~lBER) ;
':;;PUT %STR(
,.*,', STOP=&'STOP);
%GOTO M_EXIT;
%END;
29.481
30.671
~.IF ~;UPCASE(&REPLACE)
= YES
~THEN
·000;
DATA &O(';T;
KEEP &VAR _SAI1PID;
27.941
1**'': CHECK RANGE BETw"EEN START AND STOP
I - - - - - - - - - - - - - - - - -+- - - - - -+- - - - - - - - - -+- - - - - - - - - -+- - - - - - - - - - I
=>
I
1621
89,8021
554.331
27.561
I -- - - - - - - - - - - - - - - -+- - - - - -+- - - - - - - - - -+- - - - - - - - - -+- - - - - - - - - - I
ITOTAL
I 10001
299,3531
299.351
173.121
START=&.START; IF START =
STOP=&'STOP;
IF STOP
RANGE"'STOP - START;
1501
,:".
*'h~1
/*;'**,':*"I",:,·.1.,."·..*****,hH<>H,,'''',-,, ,,',*"I,,'<>h,,*,"'H'i,*,H,'I,,"''''''*'''''''**>'*''**'''*' ,'"'",, ,'..*,'''''1
1301-400
I
1571
55,3051
352.261
28.371
1- - -- -- --- - - - - - ---+------+---- -- - - --+----------+----------1
I
;'*'''1
.,,,.,*/
;,,'''''1
%RANDNUM(NUMBER=75 ,STOP=2000);
/*.,,,~
1- - - - - - - - - - - - - - - - -+- - - - - -+- - - - - - - - - -+- - - - - - - - - -+- - - - - - - - --I
1401-500
''''''''1
1**'"
I -- - - - - - - - - - - - - - - -+- - - - - -+- - - - - - - - - -+- - - - - - - - - -+- - - - - - - - --I
1201-300
'~*"I
(default=RA~NUM)
I'~*''<
I
1
I AVERAGE I STANDARD I
I
I COUNT I
SUH
I AMOUNT I DEVIATIO~ I
1------ -- - - - - - - ---+------+------ - -- -+- ---------+------ ----I
IGRDUP
I
I
I
I
I
1-----------------1
I
I
I
I
1<'= 100
I 1701
8.4821
49.891
28.191
I - - - - - - - - - - - - - - - - ,:,+- - - - - -+- - - - - - - - - -+- - - - - - - - - -+- - - - - - - - - - I
1101-200
SAS data set name for output
Starting or lowest number
**"'1
(default:1)
*""'1
STOp:
Stopping or highest number
-1.1'-;'1
t.;mlBER=
Number of random numbers made *"""/
VAR=
Variable name for random
*"""/
numbers (default=RANDNU~!)
*'>*/
**'':1
REPLACE= Specifies replacement.
With REPLACE=YES, dUplicate
*.,,*/
numbers may be generated.
*>b~/
With REPLACE=:o,m, all numbers ,,*,.,/
generated will be unique.
,,,.,*/
Specifies the number that is -I'*,~/
SEED:o
used as the seed to the
-1",,*/
random number function.
It
-:"'*1
should be 0 or a five-, six-, -{",*/
or seven-digit odd integer.
;",*/
If SEED=O (default), then the ,·,*"1'1
compUter <;lo(;k will determine *"""1
seed.
,"*"1'1
Fll\CTION= SAS function name. Code either,"'H'1
i,.,,,,/
RANUNI or UNIFORM.
1*'''*
TABLES GROUP ALL= 'TOTAL , ,
OUT'"
START=
I""~*
CLASS GROUP;
VAR ANO\J:-lT;
-1'*'''1
f'**1
-:"'*1
;""*1
***1
*-1'*1
**"1'1
'''**1
%RANDNUM(Ol'T=,
START=,
STOP=,
NUrJBER=,
VAR=,
REPLACE=,
SEED=,
Fl'NCTIO:\'"") ;
'~*"I
I"""
/*.;:*
RUN;
FROG TABULATE;
,.,,.,'1'1
"""I
;""'''1
-In'''''1
*""':1
*"*1
none.
A
*~""I
-;,i,,':
I
THEN START = 0;
THEN STOP = 0;
IF RANGE > 0 AND R&\lGE > &NUMBER THEN DO;
DO 1=1 TO &NUMBER;
&VAR"'ROUND((&FUNCTION(&SEED)"RANGE),1)
_SAHPID+l;
OUTPUT;
END;
END;
ELSE DO;
FILE LOG;
PUT 'ERROR: INVALID RANGE'
START=' START I
STOP=' STOP;
END;
RUN;
%END;
502
+ START;
DATA _NULL-;
COt.:FID::::&CO;';TID;
%IF '::oUPCASE(&REPLACE} '" ~O %THEN ~DO;
DATA &OUT;
IF CONFID >
THEN COl\FID-CONFIDI 100;
;
EXPERR=e.EXPERR; IF EXPERR >
THEN EXPERR=EXPERR/IOO;
PRECISN::::&PRECISN; IF PRECISN > 1 THEN PRECISl\=PRECISN/I00;
R=(PRECISN/COt<;FID l"CPRECISN/COKFID) ;
N=(EXPERR'"( 1 ~EXPERR»I (R+( (EXPERR"'(l~EXPERR)/&POPSIZE» j;
S=IST(l\)+l;
CALL SY~IPL'T(' SA,1PSIZE' ,:\);
STOP;
RUN;
%PUT ;;;STR ( -Iri""''''''''''"ci:*~<*,·dri''Wti"w'·:''":**,'<-/ri,*'",*1''i':-f:,Wrl''":**'':'"ci:''''"'*"I'';''W');
%PUT %STR(
*,H, PRECISN=&PRECISN);
%PGT %STR(
-1<.;,* POPSIZE::::&POPSIZE);
%PUT %STR(
*** CONFIO=&CONFID);
%PUT %STR(
EXPERR::::&EXPERR);
%PUT %STR(
SAMPSIZE::::&SAMPSIZE);
%GOTO M...F.XIT;
%END;
CO~FID=PROBlT((1~CONFID}/2)
KEEP &VAR _SAMPID;
l'i':-f"~ CHECK RANGE BETWEEN START AND STOP '''**1
START:&START; IF START '"
THE~ START:::: 0;
STOP---&STOP;
IF STOP
THEN STOP = 0;
RANGE=STOP ~ START;
IF RANGE :> 0 AND RANGE > &NutIBER THEN DO;
K=&NUMBER;
N=RANGE;
DO I=START TO STOP;
PROB=K/N;
IF &FUNCTION(&SEED) < PROB THEN DO;
&VAR=I:
_SMlPID+1:
OUTPUT;
K=K~l;
END;
%IF &TYPE :: VARIABLE %THEN ~~DO;
%IF &'PRECISt>< = . OR &CONFID =
OR &POPSIZE ::
OR &VAR =
;;;THEN %DO;
%PL'T %STR(ERROR: VARIABLES WITH MISSING VALUES ARE REQUIRED);
%Pt:T %STR(
i,,'m PRECISN=&PRECISN);
%PUT %STR(
**,., POPSIZE::::&POPSIZE);
%PUT ;;;STR(
-«*"i' CONFID=&CONFID);
%PUT %STR(
*~<* VAR=&VARj;
%GOTO M_EXlT;
%END;
N=N~l;
ENO;
END;
IF RA~GE < 1 OR RA.'\GE < &t'lC~IBER THEN DO;
FILE LOG;
PUT 'ERROR: It-.'VALID RA~GE'
START"" START I
STOP=' STOP;
END;
RUN;
%END;
%LET SIZE=50;
%l'LEXIT:
%MEND R/u'lDNllM;
IWI,,": GET DATA SET SIZE '''"'''''1
DATA _NULL-;'
X+l;
SET &IN POI1'<'T=X NOBS=~.iOBS;
CALL SnIPUT('NOBS' ,NOBS);
STOP;
RUN;
%SAMPS I ZE Macro
%IF &l\OBS < &SIZE ':'~THEN ~~DO;
".PUT '~STR(ERROR: PRELHIINARY SNIPLE EXCEEDS DATA SET SIZE);
%PUT %STR(
*,',* SIZE::::&SIZE);
%PUT %STR(
*** NOBS=&NOBS);
%Goro /LEXIT;
%END;
%MACRO SAI1PSIZE CIN=_LAST_,VAR=. ,TYPE"'. ,PRECISN=. ,POPSIZE::.,
CONFID=. ,EXPERR=.);
1'~"Im,:·,~~.."...,~**,h"''<>'ri,,·,...,:·,~~"-/:,H"**'",**i'i'i,*·ld''h'<>'ri'**".~,":**,":h'<**"l"":,",**,":,";ici,,',*
Ihh' Sample Size Macro ~ will calculate sample size for
1*'":'':
unrestricted random sample for either attribute or
I**"
variable testing.
li,-/ri,
1*''<';'
INPUT:
SAS data set i f TYPE=VARIABLE
I*'~'"
I'''''C':,
I",.;",
1*'''''
1*""':
1'"'*'"
1*'":('
OUTPL:T:
Sets macro variable
on log.
and prints il:
1'~'*1
*''''":1
,,<>·,,"1
"':**1
i""'*1
*,""1
1*** DRAW SAMPLE
DATA SSIZEj
l'i':-f'*
1***
1*'''*
1***
1***
-:'SM1PSIZE (1:\=,
VAR=,
TYPE=,
PRECISN=,
POPSIZE=,
CONFID=,
EXPERR=);
where
IN=
/''''';'-:'
/*1'*
1''''''":
VAR=
1***
TYPE::::
1***
I*''''~
PRECISN=
POPSIZE=
CONFID=
EXPERR=
EXA~IPLE:
SAS data set name for input,
required if TYPE::::VARIABLE.
Variable to be estimated,
required if TYPE=VARIABLE.
Type of testing: code as
ATIRIBUTE or VARIABLE
Sampling precision or error.
Estimated population size.
Confidence limits.
Expected. error rate.
%SM!PSIZECPRECIS~=2,CONFID=9S,POPSIZE=9000,
EXPERR=l, TYPE=ATIRIBUTE);
***1
I
**"/
*,b':l
l'h'<'·<*;"·<*-{".,..;..-::*I:-i,.;,......:,,Ht"/t,',.;,·"I,·.":,"'*,',,"drlt;,***,"*irl:,'rlt;,,"*"r.WrI,~, I
1****-I:-!",m,,,,,,,,·.':'~~"":"'**":i:i""<*-I,**"";"-:'**-I""*",rI'i'**",,**,,,,'rlt,"'''"Im
,'riti'l
,',*"" I
1,"<'Irl: From "SAS Views: SAS Processing"
I"'*" 1983 edition, SAS Institute, p. 272
*~-*/
VSAGE:
1'".",:
1""*'"
1''**
1**"
1*''''*
1*'*''<
1'':**
1*'":*
SA~IPSIZE
"',,',,,<>', I
"/",-:, /
'\":""'1
i,I""" I
*'''*1
KEEP &.VAR;
RETAIl\ K N;
SET &I:O'j
mh",/
,':-I:-!, I
***/
*'":'':1
**'":1
irlri'l
K=&SIZE;
N::::&NOBS;
PROB::::K/Nj
IF UNIFOR~I(O) < PROB THEN DO;
_SMIPID+lj
OUTPu'Tj
*,"<*/
*"I"~I
'''*;<1
***/
K=K~I;
***1
***1
***1
***/
**'":1
***1
***1
END;
N=N-lj
**'~I
I'''''~*
SAS Institute Inc. ,'rlt'''1
l,w,***,*********;",,****",""''rlrl<'·,",":"iri'i''~***',,'rlrit'",****I:-I."*i'''rlt-.''**'''''''''''"'*"I' '***i'** I
'::oLET TYPE=%llPCA!jE(&TYPE);
%IF &.TYPE ~= A'li'RIBUTE A.ND &TYPE ~= VARIABLE ~THEN %DO;
'tPUT -::'STR(ERROR: TYPE VARIABLE IS INVALID);
%PUT %STR(
TYPE::::&TYPE);
%GOTO :LEXIT;
;';;END;
*-
%IF &TYPE :: ATTRIBUTE ~~THEN ':'.;00;
%IF &'PRECISN =
OR &POPSIZE =
OR &CONFID :: .
OR &EXPERR '" . :!THEN %DO;
%PUT %STR(ERROR: VARIABLES WITH MISSING VALUES ARE REQUIRED);
%PUT %STR(
**it PRECISN::::&PRECISN);
%PUT %STR(
*** POPSIZE::::&POPSIZE);
%PUT %STR(
**,": CONFID::::&CONFID);
%PUT %STR(
**-, EXPERR::::&EXPERR) j
%GOTO M_EXIT;
%END;
RUN;
PROC UNIVARIATE DATA=SSIZE NOPRINTj
VAR &VARj
OlITPUT OUT=SSTD STD=STD;
RUN;
DATA ~ULL-;
SET SSTD;
CONFID=&cONFID; IF CONFID > 1 THEN CONFID=CONFID/IOO;
CONFID=PROBIT{ (1~CONFID)/2) j
PRECISN=&PRECISN;
R=(PRECISN/STD)*(PRECISN/STD) ;
CONFID"'CONFID*CO!\'F ID ;
N=l/«R/CONFID)+(l/&POPSIZE» ;
N=INT(N)+1;
CALL SYMPUT('SMIPSIZE' ,N);
CALL SYMPUTC'STDDEV' ,STD);
STOP;
RUN;
?;,PUT ""STR(
***;'*"i,<{""<*f",<*,':**"Irl'*"lrl,****,,,***,,<**,,,**,'rlrl<*,",****,,,.,***) ;
%PUT %STR(
*",,:
':'~PUT ':'~STR (
***
;;;P{;T ~~STR(
***
%PUT ~oSTRC
.,,*1,
\Pl;'T ~STR(
%GOTO ILEXIT;
tEND;
%M_EXIT:
%MEND SAMPSIZE;
503
PRECISN::::&PRECISN);
POPSIZE::::&POPSIZE);
CONFID=&CONFID);
STDDEV::::&STDDEV);
SAMPSIZE=&SAMPSIZE) ;
%RANDSAMP Macro
%SYSSAMP Macro
%:1ACRO RANDSAl'!P (IN"'_LASL, OUT==RANDSA:1P, S IZE=. ,SEED=O) ;
/,<,*",,,bh',-{,,,,*,,,,'Irln'<>"'<*,·,,"'Ic1''':,,'''''''i'''''''';''''irlrl<"f,,·,*"''''''',,·,,·,,"""'''''*''''''*',''''',,*,",i "-;,1"',,,,,~ "',,"1
1*""'" Random Sample Macro -
~'il1
select a random sample from
a SAS data without replacement.
1m',,"
;**,,,
r''i''~
%:1ACRO SYSSAMP (IN'"_LAST_, OUT"'SYSSAHP,
START=RA~DO:1 ,SEED"'O);
I
records from a SAS data set. This is also referred
to as interval sample. Starting record can be
random if desired.
A SAS data set.
""""'1
OCTPG'T:
A SAS data set.
-I,M,!
,',,'d: I
I:';PCT:
Ol;TP!.:T:
SIZE=,
,',-:,,'c /
**;'1
,h"*/
SEED=);
,h,*/
i<"ld,/
USAGE:
~~RA;';DSA:!P
I"""'"
r"·'···
(Ii\'''' ,
OCT=,
I'~"""
/i<>""
l'SAGE:
/''''''''
where
IN""
OUT=
1*''''''
r"h'.-
1'':-;'"
I,n,*
I,"rlri,
1''<'''*
1*''<>' EXM1PLE:
1*''<>''
1*'·"',
''''''-;'-1
i,-I,,', /
''';''''/
"''1,,''/
";SYSSMIP
i.IF &SIZE =
%THE~
OUT"',
ITIERVAL"',
START= ,
SEED=) ;
*'~/
%DO;
~;PUT
%STR(ERROR: SA~PLE SIZE IS REQUIRED);
~~PUT %STR(
SIZE;&SIZE);
%GOTO tLEXIT;
%END;
where
1*'':'"
IN=
OUT'"
ji';""
I~TERVA1='
1"""*
I''''''
1"·"",
I'·'·!.-I,
START=
I''''''''''
SEEIF-
I''''''·'·
I''';''''
I,,,,b':
I''''""
ji''''''''
I,h"*
I"""""
I"",,"
l,h"'I,
EXA~!PLE:
~;SYSSAHP
ji"','I,
/*"1'.;'
rrl"" GET DATA SET SIZE ''<*''1
DATA _NULL_;
X+l;
SET &.IN POI!>.l'=X NOBS=NOBS;
CALL SY:1PUT( 'NOBS' ,~OBS);
STOP;
;,"'1
(I~=,
-:"'''''1
1**'":'-":'·I<1"·"',,'<>·,~"':'-":d"'<**"I'~"~*","h·'*'"·'*,'''·'''''':*'''~*'I"':'-":"·"''''rl:"l:<''''*,"rl''''''''*'':'-'':''b''·''''**'i.·1
"n',,"1
'":*";'1
SAS a<1ta set.
1<-/":'1
"1''''''''1
*"'*1
''<>'''*1
,'<>"*1
''''-'':'1
*'-":'1
*"'-:'1
'i.-;,,"I
'Irl""1
'1,;';'1
''''''''1
%RANDSAMP(IN=ACCTBAL,SIZE=100);
,·,·HI
*'':*1
SAS Ins t i tute Inc. ''<>':*1
SIZE=:
SEED'"
/"." .."
SAS data set name for input
(default"'_LAST_l
SAS data set name for output
(default=RANDSAMP)
Sample size desired.
Specifies the number that is
used as the seed to the
random number function. It
should be 0 or a five·, six-,
or seven-digit odd integer.
If SEED"'O (default), then the
computer clock will determine
seed.
"""-;'1
""':"1
SAS data set
;",'rl'j
I,e".""
1,,<*1,
1,-":<"1,
1*""
1*"""
1''''''':
I~TERVAL"'.
/ ,,,.:,,',,,* "'""'h'.. ,.""',,,,.., ...,,'.. *,~*,'·{".,',,..h"ic-:,-.'.-,"h·"" "',.;,.;.. ,'<>",-1,,'0',,,,* ,,':i,'I<"I, ,,.,,',,,:,',,",-1,,,, ''''', ..',,'''';'''.,/
I''''··' Systematic Sample Macro - will systematically select
"""/
It.:PUT:
J'id,*
I'"''''
""~"'I
""',1'1
I""""
/"";,,~
-"""-'1
SAS data set name for input
(default=_LAST_).
SAS data set name for output
(default=SYSSAMP).
Interval bet...'e€m records
selected.
Specify starting record
number or RA~DOli.
Specifies the number that is
used as the seed to the
random number function.
It
should be 0 or a five-, six-,
or seven-digit odd integer.
If SEED=O (default), then the
computer clock will determine
seed.
"""I
'b'd'i
,""d'i
,"'",-1'1
*'1""1
-IH"'I
""'''''1
''''''''I
,d,," I
-}""*I
'1,,':'1'1
*,"'1'1
*'-":'1
,,,,w'l
,,,,h"1
,"m"1
'''''''1
*,""/
*"'''":1
'1:"1:'''1
**,,/
'1''1,''';
'1,,':'1<1
"'''''i'l
SAS Institute Inc. '''''ri'l
.;"'"'"'"',,,,.;,,',,,,,',,','1 ..,·:.-,h,,·drl:, ,'"h'<'I"':-;,-I,,',,'d,,',-I,'I,*id,,',,,<* I
(1;';=ACCTBAL, INTERVAL"'lOO) ;
%IF &INTERVAL =
~oTHEN o~DO;
";.PUT ~;STR(ERROR: SAt!PSING I:\":"ERVAL IS REQCIRED);
~:,pUT ~,STR(
,W,·.', I};TERVA1='e.',:;TERVAL);
~~GOTO ~LEXIT;
~oE~D;
I*id' DRAW SAMPLE BY RECORD NUMBER *",,,', /
DATA &OUT;
RU~;
%IF &NOBS < &SIZE %THEN %DO;
%PUT %STR(ERROR: SAMPLE SIZE EXCEEDS DATA SET SIZE);
%PUT %STR(
*,,<* SIZE;&SIZE);
%PUT %STR (
,"'''* NOBS"'&'NOBS);
%GOTO M_EXIT;
%END;
%IF %INDEX(%UPCASE(&START) ,R) %THEN ~WO;
RECNU:-t= INT (UN IFOR.-'1 (&SEED) ''<& INTERVAL) ;
%END;
%ELSE %00;
RECi-lUM=&START;
%END;
1.1"", DRAW SA:1PLE "'''''1
DATA &.OUT;
DO WHILE (RECNUH<TOTREC);
SET &IN POIl'.T=REC~UH NOBS=TOTREC;
_SAl'!PID+l;
OUTPL'T;
REC;\'U~!+&I~TERVAL ;
END;
STOP;
RU:-.I;
1","*'·'·;"''''''''*'''*"'''''''''''''·,,·:"I:'·'-i··,,<{,*·;,,'','',"rl<1<>h"',h·"'.. ,'<'I<>'d,,,·,·.':,':-iH,,'-'·'*"" I
1"'** From "SAS Views: SAS Processing"
,"'1<1'1
;-.'<".'d, 1983 edition, SAS Institute, p. 2.72
,,-Id'i
I,H",
,',-;"n',,', "·""·;'*'h'"'.-""·",..,""-;,,h·...,,,',',,,
"'"h,,,,',,', I
DROP
1..: PImE;
RETAI:-; K ~;
%rLEXIT:
%I1END SYSSAMP;
SET ∈
K"'&SIZE;
N=&NOBS;
PROB=K/N;
IF UNIFOR~1(&SEED) < PROB THEN DO;
_SAMPID+I;
OUTPUT;
K=K·l;
E!>:D;
N=N-l ;
%MUSSAMP Macro
%!1ACRO MUSSAl1P
(I~= J,ASL ,O~~!US ITE~j
,VAR='. ,
rlATERL=. ,EXPERR=. ,CONFID=. ,CELLWID1':o.);
/*""",-":"";rl:;,,,,* .."*,'"'·,·",:,,<·.;·,"''''''''H,,·,,h"rl,,'c*;,,'',·,'I,,hh'd,,·,,n'',':'lHd,,\-;"'""rl<-.':>",,,,,,,,",--;,,,<>',{,;,,'H,',,' I
Ii'*''.- Monetary-Unit Sampling .. - Cell Sample Selection !1acro
''''''''I
I''''''''''' from "Dollar~Unit Sampling" by Leslie,Teitlebaum,Anderson ,·,,"1'1
RUN;
%!'lJ:XIT:
%I'1END RANDSAMP;
1"';:"1: If cell width is not given, it will be calculated.
''''~'I'I
1,'Hd,
I,"rl,,',
I''''''''
1'''''-;'
,"'h"1
,-":d'i
''''''''1
''''''''1
"""*1
'':'''i'l
,·,,'<'1'1
,"*,'cl
**'':1
"**1
Records are selected according to cell selection method.
Items that exceed the cell width are automatically
selected for 100% testing. These item~ t.;ill not be used
in cell selection calculations. These large items will
/",,',.;, have _SM1PID=99999.
;-;,.:,.:,
Ii",,',
1*"''''''
/''''''
/',""
504
I!'{PUT:
SAS data set.
OGTPUT:
SAS da-.::a set.
/*',.;,
USAGE;
/*~,
r,i. ,;/*'1,,"
/,,,*,,
/*,..,.,
/'ic""':
%MUSSAMP(IN=,
OUT"',
VAR= ,
MATERL"',
EXPERR"',
CONFID=,
CELLI.nDT=);
where
/*',*
/"<>'<1,
1**'1,
/,'riri'
/,h,*
/1,-1",:
/'''**
/i"""~-
I~""
/*"'*
/''''''''
/-:,.:,,', GET ANOTHER RECORD IF SCBTOTAL STILL KEGAtIVE
IF Cr.;~lSUBT -: a THE(>; GOTO ADD~LOOP;
'1""\1
/,H.-I, SCBTOTAL IS POSITIVE, OCTPCT RECORD FOR TESTI(>;G ,h', 'I
AGAI~ ,'n,;, /
SUB'LPOS:
SAflPt..;U~l+ 1;
~SAMPID=SAMPNUr!;
OUTPL'T;
CELL"'MUL + 1;
GOTO NXLITE!1;
*-1,,"/
***/
1""*
INCRE.'!ENT FOR NExT CELL
'I.-{'*/
RUN;
%ILEXIT;
%MEND HUSSM!P;
1,-1'"7/
*,'<1,/
i",," /
*** /
1,·,'1,"1,
SAS Institute Inc.
'~**I
li"",*,,,*''''"ri'*'~~·*'irl<**,w.·i',,,*''·'''''''''****''''''*''<1'****''''''***'''*';,**",,,..;,.,,*,'rlrit'':,'<1<,':>'rid<>'<
~IF
,~*<,/
+ &VAR;
i'""-"" -AND SELECT
*'''*1
VAR"'M!OUNT,
MATERL=20000,
EXPERR=lO,
CONFID=95);
/".~.
*,',* /
**," /
***/
SAS data set for input, if
,'<>H,/
olIunitted then _LAST_ used.
***/
OlJT::=
SAS data set for outpUt.
***/
VAR=
Numeric variable to be sampled.··>**/
MATERL= tlateriality.
-Id-l:/
EXPERR= Expected errors.
*,'<1</
CONFID= Confidence limits desired,
*.,,,"/
CELLIriIDT=Cell width i f you do not want ,'rlrit/
the macro to calcUlate it.
*''*/
~:1C'SSA!1P(It-;=II>,'VDATA,
r"""
Cm!ST.:BT=CU~ISUBT
IN=
/-Irl'*
/,.".,.:, EXA.'1PLE:
i'"'*'," ADD ISPL'T M!Ol.':"'T TO SUBTOTAL
***/
*,,*/
i'i",,/
,,,**/
/**'"
f'i""*
*"/,*/
/
&VAR =
OR ((&rlATERL =
OR &EXPERR =
OR &CONFlD '" .)
A;'<D &CELLI{IDT '" .)
%THEN ~DO;
~~PI,;T :;'STR(ERROR: VARIABLES "'ITH :lISSIt-.'G VALUES ARE REQUIRED);
%POT %stt(
*,W<
VAR=&VAR) ;
%PUT %STR(
*'1,*
MATERL=&MATERL);
%PUT %STR (
EXPERR=&EXPERR) ;
%PUT %STR(
CONFID=&CONFID);
%PUT -::'STR(
**,,<
CELLIriIDT=&CELLWIDT) ;
%GOTO ~LEXIT;
%END;
APPENDIX IV. Miscellanous Audit Programs
***
Using PROC FSLETTER for Confirmation Letters
The FSLETTER procedure in SAS/FSP® software
can be used to produce_ dunning or confirmation
letters. The letters are entered and managed by
the user in an interactive session.
PROC
FSLETTER has a full-screen editor which is used
for editing letters or the lette~, forms.
DATA &OUT;
/"r{,,) TEMPORARY Al\'D NEw' FIELD SET UP ..'''''*/
RETAIN HATERIAL
/'1,*,', tlATERIALITY **"/
EXPERROR
CONFIDEN
UEL
CELL"'IDT
CELLW~lt:L
0
CG~ISELPT
0
PCU~ISEL
0
0;
cm!SUBT
IF
1"'-::-;, EXPECTED NU~lBER OF ERRORS ,'d "'I
/M,,·, CONFIDEz.>CE ,H,i'/
/""'''' UPPER ERROR LI:'HT FACTOR ':"~-i'l
t·,:<,,-, CELL wIDTH "'-"-'/
/"-,"--' CELL "'IDTH :lULTIPLE -,'''':''1
I,H,{, CU:1GLATIVE SELECTION POli-l! <,-:d,/
1*";' PREV CU~1ULATIVE SELECT PT '1""'1
/,H,;, CmlULATIVE SUBTOTAL *"'*1
Data in a SAS data set can be merged with a
letter in either batch or inter'active modes. When
batch mode is used, a letter is sent for each
record in the data set. When interactive mode is
used, the SEND command can be used to
selectively send letters,
In order to merge a
letter catalog with a SAS data set, the LETTER=
option must be specified on the PROC statement
for FSEQIT or FSBROWSE. The SEND= option
must also be used on the PROC statement to
specify which letter must be sent.
~N....=l
THEN DO;
MATERIAL = &t1ATERL;
EXPERROR = &EXPERR;
CONFIDEN = &CONFID;
IF CONFIDW > .9999 THEN CONFIDEN=CONFIDEN/I00;
CELLwlDT = &CELLWIDT;
IF CELLWIDT =
THEN DO;
1*'1,." CALCULATE CELL WIDTH OR INTERVAL i'*,,':/
liEL=GMlIt-V (COtWIDEN, EXPERROR+ 1) j
CELLWIDT=ROUND(NATERIAL/UEL, 1);
END;
END;
NX'LITE}I:
/,',** GET
1*1,-{,
FIND NEXT SAMPLE SELECTION POINT ***/
NUMBER BETh'"EEN a AND CELL WIDTH
(UNIFOR:1 (O),"CELLWIDT) ,1) ;
RANDO~I
RA~1)NU~l=ROm-.'D
**';'1
/'1,** CALCULATE CU~lULATIVE SELECTION POINTS *,"'*/
PCUC1SEL=CUtISELPT ;
+ (CELLWIDT
CELLWMUL);
*
CUMSELPT""RAND~{;r!
I**""~
CALCULATE SAMPLING INTERVAL "'**1
• PCUMSEL;
SA~lPIt-."T=cmISELPT
/**" START SUBTOTAL BY SUBTRACTING SAMPLING INTERVAL *>':*1
CUt!SUBT=CI.J"!1SUBT • SAMPI:':T;
IF CUi'lS!;BT >= 0 THEN GOTO SUBT~POS; 1""':* DOUBLE HIT OCCURRED of,,;"'1
A permanent data set should be allocated to store
a letter catalog. Some sites have a standard
letter catalog that contains the forms used at· the
site. This standard catalog is then copied by all
users so that setup work is minimized. If the
data set has been allocated with the DDNAME of
MYLETR and if the name given to the letter
catalog in the SAS library on the data set is
LETCAT, the letter catalog can be accessed by
entering:
PROC FSLETIER LETTER=HYLETR.LETCAT; RUN;
ADD_LOOP: 1*';-" ADD AHOliNT TO SUB UNTIL SUB IS POSITIVE **'':/
IF EOF THEN STOP;
fi""*
SET &IN END=EOF;
INPUT DATA SET, GET OBS OR RECORD ,,<**/
/*** TOP STRATUM ITEMS ARE THOSE THAT EXCEED CELL WIDTH **1'1
IF &VAR > CELLWIDT THEN DO;
_SA~!PID=99999 ;
OUTPUT;
GOTO ADD~LOOP;
END;
Any type of information in a letter can be
specified as a variable and when the letter is
merged with a data set, the variable information
is filled in automatical1y.
The names of the
variables usually match the variable names in the
letter but they do not have to match. The ATTR
command can be used to link unlike variable
505
names togethe r when the letter is being edited.
Here is an exampl e of how data is merged with a
letter catalog :
1*"/"':
1*'"'*
1*'':*
1*'''''
1'''''<*
1'''*'''''
I-M,';'
PROG FSBROWSE LETTER=LTRLIB.LETTERS
DATA=AUDLIB.ARAUDIT
SEND=ARCONFRM;
RUN;
The confirm ation Jetter would
before the data was added:
look
like
PLAN
STEPS
STEPP
1*'''"'
/,~'""~
t.,<·~;,
I*'''* EXMlf'LE,:
1''<*';'
I"m''<
1'''':*
I*'':*';-{''''',<*'
FHA Plan number:
code as FHAI
code as FHA2
c;.ode as FHA3
code as FHA4
code as FHAS
number of payment steps
percentag e increase with each
payment st.ep
,h"" I
",,,*/
,;+",1.
**"/'1
~~LOA~GPH(A:1T=50000
,APR=12, YEARS""30,
PLAN""3,FPDATE=OlClAR86);
SAS Institute Inc. *"/,*!
i~"h"""<"·,","","'"**'''''''i'''''"'<-Ici,*"/,,,,**,''''<*"/'"/''':iri,,'<>,<***,~,'''I'i''',,
.. *****"/",<,"',,*"/,,~ I
this
~;IF
&A:1T =
OR &.APR ""
OR &YEARS =
OR (&PLA:-< '"
A:';D (&STEPS =
OR &STEPP ""
%THEN ~DO;
~~PvT \STR(ERRO R: VARIABLES \o,'ITH ~!ISSING
VALUES ARE REQUIRED);
%PUT %STR(
AMOUNT=&A!1T);
%PUT %STR(
*** APR=&APR);
%PUT %STR(
YEARS=&YEARS);
%PUT %STR (
,(",<* EITHER: );
%PUT %STR(
*,,:,~ PLAN=&PLAN);
%PUT %STR(
OR: );
%PUT %STR(
,'rl"" STEPS=&STEPS);
%Pl.'T %STR (
"/<'1<>', STEPP""&'STEPP);
%GOTO !LEXIT;
%END;
.»)
***
***
&&date' _ _ _ _ _ __
&company ______ _____c-_
&addrl _____ _____ ___
&addr"2=
&city~ ===============_.
&state_ &zip __
%IF %UPCASE(&PLAN) = FHM ~·~THEN %00;
%LET STEPS=5; %LET STEPP=O. 025;
%E~O;
%IF
Dear Sir:
~-;UPCASE
~LET
~;E:-\D
%IF
Here are the details as we have them for your account
:
ACCOUNT: &acctno' _______
BALANCE: &curbal _ _ __
AS OF: &baldat e _ __
A!1T=&MIT;
Sincere ly,
Laura C. Stevens
%GPMLOAN Macro
(MiT=. ,APR=-. , YEARS=. ,FPDATE= .,
PLAN=. ,STEPS=. "STEPP"". );
..
~,""*,."",;-{"'"h.,*i«I,,"**-I,,"_t._.,,,,,",,-,.:,,'ri,,',,",
I
1-::"'"/' Graduated Payment Mortgage Amortiza tion Schedule ~Iacro
*'''*1
I''''. . . ."'
I~ . . i~'
Ii""...
I'''''''''''
1*'''"'
1'·. .'(.-";'
1*"/<'1'
I'"'""'"
1**'"
1*''<>''
ji"''!:'i,
1'""':*
I'"c":ri'
1**';'
(1"""
1*"*
1""'*
1*"'"/'
1**"/'
This macro can be used to produce amortizat ion
schedules for graduated payment loans.
It assumes
that the term of the loan and the interest rate
are
fixed and that only the payment and the balance
change over the life of the loan. For fixed rate
mortgages , use PROC ~lORTGAGE.
USAGE:
%LOANGPM(A:1T=,
APR=,
YEARS=:,
FPDATE=,
PLA","',
STEPS=,
STEPP=);
where
lRATE<=&APR;
PERIODS=&YEARS*12 ;
FORMAT POATE DATE7.;
FORHAT MONTH YEAR $4.
FOR~IAT PYl'IT INTEREST PRIN_PD PRIlCBAL COM~lS
.2;
KEEP MONTH YEAR PYMT I!>.'TEREST PRIN_PO PRIN_BAL;
PDATE="&FPDATE"D;
IF PDATE=. THEN POATE=TODAYO;
N~STEPS"'INPUT("&STEPS",3.) ;
P ~STEP=INPUT("&STEPP" ,6.4) j
IF P_STEP<l THEN P_STEP=P_ STEP+l;
ELSE P_STEP=P _STEP 1100+1;
ARRAY PV (I) PV1~PVll;
1*'"'' EDIT INTZREST RATE ,"M'I
IF IRATE<l THE:": RATE=IRA TE/12;
ELSE RATE=IRA TEIl200 j
1*** CALCULATE PRESENT VALUE FACTORS ,~,w'l
DO 1=1 TO N_STEPS;
PV=( 1 ~ 1 +RATE ),"rl, C~ t~ Cr,', 12)))) IRATE;
END;
I=N_STEPS +l;
PV=( 1 ~ « l+RATE)"/'*( ~ l*PERIOD S))) IRATE;
1=1; TEMP=PV;
DO J=2 TO N_STEPS+ l;
I=J;
FINISH=PV ;
I=J~l; START=PV;
TEMP=(FIN ISH ~START)"/' (P ~STEP''''''I )+TnlP;
E:-JD;
I'~*'~ CALCULATE-PAYMENT '·':""'1
pn1T=AMT/TEl1P;
PAY~E:-IT""PY~T ;
1*'1'""', SETUP VARIABLES FOR SCHEDCLE ",'"rl'1
PRIN_BAL=AMT;
TOLINT""O ; TOT_pnlT= O; STEP_CNT=1;
1"/'"'''' DO SCHEOC'LE '..,',,·'1
DO 1=1 TO PERIODS~l;
~!O~TH=PL'T(I>DATE ,WORDDATE3. J; YEAR=PLl( YEAR(PDA
TE),4 0);
I\TEREST=PRIN_BALi'RATE ;
PRI!CPD=P Ym ~ It>:TEREST;
PR E'CBAL=PRIN_BAL~ PR n";_PD ;
OUTPUT;
TOLIl>.'T+INTEREST; TOT_pnlT+ pn1T;
IF PRIN_BAL > HIGH~BAL THEN HIGH....BAL=PRIN-..BAL;
IF I=STEP_CNT>~12 TIfEN DO;
IF STEP_CNT <= LSTEPS THEN pnlT""PYl1T>'<P_STEP;
STEP_CNT +l;
END;
«(
li~' ,~"h",~,~''<*~,,''*,.'"',*,',*,"'*~,,',<,<,,''''<>H''*
"/,i<i<*_t._.~"/,,
l'fri';'
1'". . ,.,
~.l.'PCASEC&PLAN)
OPTIONS LS=80;
DATA LOAN;
LENGTH MIT 8 IRATE 8 PERIODS 8;
If this informa tion is nut correct , please make the
necessa ry correct ions, sign and return ~his letter.
Thank you.
GP~lLOAN
(&PLAN) ::: FHA2 %11IE;'; %00;
STEPS=5; ~;LET STEPP~O.050;
;
= FHA3 'aHE~ %DO;
%LET STEPS=5; %LET STEPP=0.0 75;
%END;
%IF %UPCASE(&PLAN) = FHA4 %THEN 'JlO;
%LET STEPS=10; ~;LEr STEPP=O.0 20;
%ENO;
%IF %UPCASE(&PLAN) "" FHA5 %THEN %DO;
%LET STEPS=10; %LET STEPP=0.0 30;
%END;
Our interna l auditor s are request ing that you verify
the informa tion in our files ,for your account .
%.'!ACRO
AJIT
APR
YEARS
FPDATE
>h"*l
***1
*-{,,"I
*'''"'1
*'''''1
''''''*1
''<**1
**"/'1
***1
***1
*,~* I
,h'mI
***1
**-1'1
***1
amount of loan
annual percentag e rate
number of years
first payment data (opt)
code as DDMMMYY
"/ri"~1
***1
*'''*1
'''''*1
''<**1
***1
***1
"/"'<>"1
""...'1
,'d,* I
''<**1
*'':*1
**""1'1
""""**1
**'~ I
506
LOAN DETAIL
PDATE=INTNX( '~!oNTH' ,PDATE, 1);
END;
MONTH=PlJT(PDATE ,WORDDATE3.); YEAR=PUT(YEAR(PDATE),4 0);
INTEREST=PRIN_BAU'RATE ;
PYMT=PRHLBAL+ Il'<TIRESTj
PRIN_PD=PYMT· INTEREST;
PRIN_BAL=PR IN_BAL~ PRIN_PD ;
TOT_INT+INTIREST; TOT_PnlT+PYMTj
OUTPUT;
I'h~" LOA."I SmL.'1ARY -Irlr{, I
FILE PRINT;
TITLE2 'LOAN SUMHARY' j
PUT
III
II
II
II
II
II
II
II
@18 'A.'10UNT OF LOA..\".
@45 AMT
@18 'HIGHEST LOA.-': BALA:\CE.
@45 HIGH_BAL
@18 'ANI-."UAL PERCEI-."TAGE RATE.
@55 IRATE
@18 'PERIODIC RATE .......... .
@51 RATE
@18 ':\l)}!BER OF PAY~lEl'<TS.
@55 PERIODS
@18 'TOTAL PAYMENTS.
@45 TOLPYMT
@18 'TOTAL INTEREST. . . . . . . . . . .. @45 TOT_INT
@22 '---~--- PAYME1>,"T SCHEDULE -------';
DO 1=1 TO S_STEPS;
PuT @18 'YEAR' @23 I 3.0
@45 PAYME:-""T CO~!~!A15.::';
PAY~!E)"'T=?AY~IE!\'T":'P _STEP;
END:
PUT@18 'YEAR'@23 I 3.0
@45 PAYMENT COI1MAI5. 2 j
YEAR
PAYMENT
~O!\'TH
1986 MAR
"
"
""
395
395 69
APR
MAY
395 69
395
395 69
395
395
395 69
395 69
395 69
"'"'
Jl.:L
AUG
SEP
OCT
~ov
DEC
COMMA 15
COM:1A.15
5.2
9.8
5.0
Cmll1A15
COM!1A15
INTEREST
PAID
PRI),;CIPAL
PAID
PRINCIPAL
BALANCE
500.00
501.04
502.10
503.16
504.24
503.32
506.42
507.52
508.64
509.7i
-104 . .31
-105.36
-106.41
-107.47
-108.55
-109.63
-110.73
-111.84
50,104.31
50,209.5;
50,316.08
50,42.3.55
50,532.10
50,641.73
50,752.46
50,864.30
50,977.25
51,091.34
------ ----------.. _3,956 88
5,048.21
-~-------
1986
"N
1987
FEB
~112.96
----
-114.08
-~ -~~~~~~--
·1,091 . .34
395 69
S>O 91
-115
395 69
.512
-116
"'
""
.51,206
5 L, 322
""
'0
save printing.
Output compressed
~lacro "'ill produce full Schedule.
'+ , ............... .
2015 JAN
Foe
RUN;
MAR
TITLE2 'LOAN DETAIL' j
PROC PRINT DATA=LOAN SPLIT=' t ;
BY YEAR NOTSORTED;
SUMBY YEAR; 10 YEAR nONTH;
VAR PYMT INTEREST PRHLPD PRIN_BAL;
SUM PV!1T INTEREST PRI~LPD;
LABEL YEAR=' ,"YEAR t
*
APR
MAY
JUN
""L
AUG
5EP
OCT
)-;OV
~!oNTH="~MONTH'
PYMT= ' *p AYM£NT '
INTEREST=' INTEREST'~PAID'
PRIK_PD=' PRIl\CIPAL"'PAID'
D" ----- --
568 00
568 00
568 06
568 06
568 06
568 06
568 06
568 06
568 06
368.06
568.06
368.06
73
88
PRI~CBAL='PRISCIPAL'~BALM';CE' ;
58
------
6,816 73
2016 JAN
RUN;
~-- ~-
%HEND GP:1LOAN;
2016
%GPMLOAN(AHT=50000 ,APR=12, YEARS=30, FPDATE=O 1!1AR86, PLAN=FIiA3)
%GPMLOAN Macro Output
-~~------
1,1.36.
-~~~~------
549. 14
11
556.87
562.44
"
~--_.- -------~~
16 82
"
----
6,892
6,393
5,889.44
5,380.28
4,866.02
4,346.62
3,822.02
3,292.18
2,757 04
2.216 55
1,670 66
1,119 3D
""
6,267 . .59
62
-- --------
~~
-- -----_ .. ---
562.44
0.00
1,119.30
-~-=
197,991.92
j
53.80
48.66
43.47
38.22
32.92
27.57
22.17
16.71
568 00
588 06
FEB
%~LEXIT:
"
" ""'
-~-~----
2013
494.
499. 13
504. 13
509. n
514.26
519.40
524.59
529.84
5.35.14
.540.49
545.90
531. 35
""
147,997 92
50,000.00
%XREF Macro
%MACRO XREF (PROCLIB=,OUT=XREF, SELECT=. ,SORT=.);
LOAN SUMMARY
I'~*'I;-I:*'~*H"'*'I"·"·,*,"""~'~'~'''~C"I"·,**,,,'''·C"I'·:''~"I'*
:,,"**'·,,·,,;'[,,""';,[""'W"·""i,·:,~, I
I'h,* Cross-reference ,'iactco 1**'"
A.'10Ul'T OF LOAN.
50,000.00
I'i."'~'"
HIGHEST LOA",
53,935.41
I'''-Irl'
12.00
r'*'~
.01000000
1*'-""
I,h".,
I'~"'~'
BALA~CE.
I'~**
•...,"SUAL PERCEC\,AGE RATE.
PERIODIC RATE.
NUMBER OF PAYMENTS.
197,99792
TOTAL INTEREST.
141,99192
I'~''''~
r"h"
1*'''·'
1''**
1'''**
1**'"
Im"*
1,;.[,0{<
I,,-Iri<
1*''*
PAYMENT SCHEDULE
YEAR
YEAR
YEAR
YEAR
YEAR
YEAR
6+
*,H'I
ISPt.'T:
I''''''~
3"
TOTAL PAYMENTS.
will print report and output
*'-""1
data set of proc names and the programs used in the
-:;-1:':'1
procs.
It also lis"ts the non-temporary data set
*';.['1
tha"t are used in the procs (i.e. DSNs not containing ·:"H'I
&&).
This macro uses the SO(JRCE procedure in SAS
*'~*I
software which is limited to 80~byte, card~image proc "Iri"~1
librarie~.
This macro only works unde!' OS.
*'1"·'1
395.69
42.5.36
457.2.7
491.56
52.8.43
568.06
I' . . . ."."
OUTPUT:
WORK:
FILE
An PROG or JeL par"ti"[:ioned data se"t libra.ry
thnt has SO-byte racords only.
"':-I,..,~ I
*''*1
***1
~,-{,* I
A temporary file that is used to store the
-Irl""1
unloaded library before the search takes place. **"'1
I f this macro is run in batch mode, "then a
-:.**1
temporary file must be allocated with the
DDNANE of STHPLIB.
*'~*I
*"**1
-"'~I
USAGE:
%:o.."REF{PROCLIB=,
OUT::,
I''''~'''~
SELEGT:. ,
SORT=.) j
I'~**
**1'1
***1
~d,," I
*,,'''1
**"1
I'''-Irlt
PROCLIB= DDNAHE of PROC or JGL library ~"'*I
to cross~referenced.
***1
SAS data set for output
**"1
List(5) of members to be
**"·~I
searched. Review the SELECT
***1
s"tatement of PROC SOURCE for
~'*'''I
proper coding of this parm.
*'1'*1
SORT=
Type of sorting requested for **'1'1
report or output data set.
*''''~I
Enter PROG, PGH, or DSN in any *'~*I
order ... ith a space between the -/d'*1
words.
***1
I*{'*
*"*1
li'**
1*",,·,
I*~"~
1''''',*
I'~**
I~"'''~
I*'''~
1'"'**
507
*""~I
A SAS data set and printed report of the procs
and programs that have been cros~-referenced.
11."'~*
I'·"...."
IH,*
I*,d,
1***
"""'~I
where
OUT=
SELEGT=
I~"~*
EXMIPLE:
I'm"
1';"'*
1",-;,,·,
I'"''''
IF INDEX (A-REC , 'PGM"") THEN DO;
1''<-1", GET PG!1 NANE *"""/
PTR=INDEX(A_REC,'pml=') + 4;
FLAG"'l;
DO WHILE (PTR<72);
CHR=SUBSTR( ILREC,PTR, 1);
IF CHR 1\OT= ' , AND CHR NOT=:' " THE~ DO;
PGi'I=TRI:1(PGM) IICHR;
PTR+l;
E!:';D;
ELSE PTR=lOO;
END;
END;
,,,H<1
''''''*1
%XREF (PROCLIB"'~IYLIB,
SELECT=S: ,
SORT=:PROC PG~I DSN);
~/
*'#*1
;';""1
"",,,,,,,,,,.,;,,"'h·,,·"',,':;,, ,"'1"""""'''''''''''-;'1
SAS Institute Inc.
I;"~' ,~,','h"·.,.;,·:,·."·"
,·;,·;,-.,,·;,·;,';"."';,·,'<'!d,;';'·;'·" '-;'·;"'rl
%IF &PROCLIB::
OR
%PUT %STR(ERROR;
%PUT %STR(
%PUT %STR(
%PUT %STR(
,,:{,,,:
%GOTO !LEXIT;
%END;
,"**
%THEN %DO;
&SELECT = . OR &SORT =
VARIABLES WITH MISSING VALUES ARE REQUIRED);
PROCLIB=:&PROCLIB);
SELECT=&SELECT);
SORT"'&SORT);
%LET SELECT=%UPCASE(&SELECT);
%LET SORT"':~UPCASE (&SORT) ;
%DO 1"'1 %TO 3;
%LET ORDER&I'" ;
%LET ORDER&I=':;.SCAN(&SORT,&I,' ');
%IF (&&ORDER&I ~'" pm! & &&ORDER&I ~= PROC & &&ORDER&I
OR &&ORDER&I '" ·",THEN %[)O;
%PL'T ':;.STR{ERROR: SORT PARA~!ETER IS NOT VALID);
%PUT ~.5'rR(
SORT--&SORT) ;
%GOTO CLEXIT;
".END;
IF INDEX (A.-REC, 'DSN=') THEN DO; I*'~ GET DSN fI,,,,': 1
FLAG"'O j
PTR=INDEX(~REC, 'DSN=') + 4;
IF SUBSTR(A_REC,PTR,2J = '&&' THEN GOTO SKIPOL'T;
DO WHILE (PTR<72);
CHR=SUBSTR(A_REC ,PTR, 1);
IF CHR NOT= ' , AND GHR [,;01<=',' THEN DO;
DS~=TRIt1(DSN) II CHR;
PTR+l;
END;
ELSE PTR=100;
DS:'<)
Dm;
OUTPUT;
SKIPOCT:
E~IJ;
%E~D;
RC~;
I~d"" READ LIBRARY
TO GHECK DSORG AND GET DSN FOR REPORT TITLE
DATA _NULL_;
FOIliIAT JFCB $CHAR200.;
INFILE &PROCLIB JFCB=JFCB RECFM=U;
LIBDSN';'SUBSTR(JFCB, 1 ,44);
CALL SY}!PUT(' LIBDSN' ,LIBDSN);
IF SUBSTR(JFCB,99,1) = '.1. ..... 'B THEN
CALL SYMPUT{ 'DSORG' , 'PS');
ELSE
IF SUBSTR(JFCB,99,l) = ' . . . . . 1.'B THEN
CALL SYMPUT('DSORG', 'PO');
ELSE
IF SUBSTR(JFGB,99,1) = ' .. 1. .... 'B THEN
CALL SYMPuT('DSORG', 'DA');
ELSE GALL SnIPUT( 'DSORG' , 'U~KNOWN');
STOP;
RUN;
%IF &DSORG ~= PO %TIlEN %DO;
%PUT ~~STR(ERROR: LIBRARY r!CST BE PARTITONED DATA SET);
%PUT %STR (
',,,,"'" DSORG=&DSORG);
%GOTO ~CEXIT;
%Et'.'D;
''rl''''1
/,,""'" SORT A:\D PRI~l X-REF DATA "'{<-!'I
TSO FREE F(ST~lPLIB);
PROG SORT DATk=&ODT Ol'T;¢OUT;
BY &ORDERI &ORDER2 &ORDER3
RUN;
TITLE2 "GROSS-REFERE:';CE LIST FOR LIBRARY = > &LIBDSN";
SELECT LIST = > &SELECT";
TITLE3 "ORDER ="'> &SORT
PROC PRINT DATA"'&.OUT SPLIT;' , LABEL UNIFORM;
BY &ORDERI &ORDERZ;
ID &ORDERI &ORDERZ;
VAR &ORDER3 l1E~lBER;
LABEL
PGc!=' PROGRAN NAME'
PROG"" PROC NAl'lE'
DSN='DATA SET NA,m'
ME~IBER=' tlEtIBER OR ALIAS' ;
RUN;
j
%tLEXIT:
%:·IEND XREF;
1""*-1,
ALLOCATE WORK FILE lu'lD EXTRACT MEMBERS ,''',.;,/
TSO ALLOCATE FILE(SH1PLIB) UNIT(DISK) SPACE(5,5) CYLINDERS;
RUN;
PROC SOURCE INDD=&PROCLIB O(;TDD=Sr.1PLIB NOPRINT',
SELECT &SELECT;
RL'N;
Sample Output from %XREF Macro
CROSS-REFERE.... CE LIST FOR LIBRARY ==> SYS2.JOBPROD PROCLIB
ORDER ="'> PROG PGf! DSN
SELECT LIST ==> $:
1"'**
READ UNLOADED LIBRARY AND BUILD X-REF DATA 'h~*1
DATA &OUT(KEEP:&ORDERl &ORDER2 &ORDER3 MEMBER);
LENGTH ME~lBER $ 8 PROC $ 8 PGM $ 8 DSN $ 44;
LENGTH GHR $ 1;
RETAIN ~lEMBER PROG PGM;
RETAIN FLAG 0;
INFILE snlPLIB;
INPUT @l ~REC $CHAR72.
@1 TEST
$CHAR2.
IF TEST"" .1' THEN DO;
1;"''* CO;ITROL CARD {"'",, /
IF FLAG"'l THEN DO;
FLAG=O;
DSN='NO DATA SET NAi'lES FOR PROC';
OUTPUT;
PROC
NAME
PROGRAM
NAME
DATA
SET
t\MIE
l1E}lBER
OR
ALIAS
$S$$sm
FC0048
NO DATA SET NMIES FOR PROC
S$$$$Ml
$$$S$OX
ZZZ1l8X
E~D;
PTR=I~DEX(ILREC, '~A~lE=') + 5;
MnIBER=SDBSTR (A_REC, PTR. 8) ;
IF INDEX (ILREC, ' ADD 'J THEN DO;
j'hH' NEW HE!1BER NAME, CLEAR ALL -1,*,"1
PGt1=' '; DS~=' '; PROC'" , ';
END;
IF INDEX(A-.-REC,' ALIAS ') THEN DO;
I*i'" ALIAS NAME, PRINT ~lESSAGE *,b"l
DSN""MEMBER NAHE IS ALIAS FOR PROC';
PGH"" .
OUTPUT;
END;
SSS TAPECOPY.LABELT
SSS TAPECOPY. LBLINFO
SSS. TAPECOPY .:·!AILT
SSS. TAPECOPY . SORTJOBS
SSS. TAPECOPY. TAPESAVE
SSS. TAPECOPY. TAPLNGTH
SSS. TAPEGOPY. VOLINFO
SSS. TPCOPY4. CNTL
SSS. TPCOPY4. CNTL(TAPLABEL)
SSS. TPCOPY4. LOAD
SSS. TPCOPY4. MIXES
SSS. TPCOPY4. RECOVER
SYSl.SORTLIB
MEMBER NAME IS
MEMBER NAME IS
ME~IBER NAME IS
MEHBER NAME IS
MnlBER NMIE IS
MENBER NAME IS
$$$$$OX
ALIAS
ALIAS
ALIAS
ALIAS
ALIAS
ALIAS
FOR
FOR
FOR
FOR
FOR
FOR
PROC
PROC
PROC
PROC
PROC
PROC
$$$$$OX
$$$$$OX
$$$$$OX
$$$$$OX
$$$$$OX
$$$$$OX
$$$$SOX
$$$$$OX
$$$$$OX
$$$$$OX
$$$$$OX
$S$$$OX
$~$$$OX
$$$$$01
$$$$$02
$$$$$03
$S$$$04
$$$$$05
$$$$$06
END;
IF INDEX (A_REC,' PROC ') TIlEN DO;
PTR=3;
DO WHILE (PTR<72);
CHR=SUBSTR(A_REC, PTR, 1)
IF GHR NOT= ' , THEN DO
PROC=TRIM (PROC) II CHR
PTR+1;
1*1,,·, GET PROC NAtJE '''',,''1
$$$$SIX
END;
ELSE PTR=lOO;
END;
END;
508
ZZZ1l8X
SSS TAPECOPY LABELT
SSS TAPECOPY LBLINFO
$$$$$IX
$S$$$lX
Download