INTRODUCTION - sasCommunity Drewry.pdf · Because the number of ... the format of the records in...

20
The SAS System as a Tool for the Financial Systems Auditor Ferrell Drewry SAS Institute Inc. INTRODUCTION 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 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 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 Generalized software has been developed_ for auditing 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 Later versions of generalized audit software packages were developed using fourth-generation 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 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 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 that have been developed with SAS software can be found in the appendices of this paper. 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. 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. TASKS PERFORMED BY GENERALIZED AUDIT SOFTWARE 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. 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.

Transcript of INTRODUCTION - sasCommunity Drewry.pdf · Because the number of ... the format of the records in...

The SAS System as a Tool for the Financial Systems Auditor

Ferrell Drewry SAS Institute Inc.

INTRODUCTION

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

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

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

Later versions of generalized audit software packages were developed using fourth-generation 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

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

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.

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.

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.

TASKS PERFORMED BY GENERALIZED AUDIT SOFTWARE

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.

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.

Specifically, the auditor will need:

to test the accu racy of the data

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

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. 7

Trend analysis, project scheduling, automatic creation of confirmations are examples of additional features found in existing audit softwa re packages.

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.

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.

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), 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

required to extract data from files when there are multiple record layouts within the same file.

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.

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.

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 file. 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.

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:

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;

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:

DATA; %ACCTBALj IF TRDATE='31JAN86'D;

PROC PRINT; RUN;

For all records:

COLUMNS FOmlAT

01-02 character 03-05 character 06-08 character

DESCRIPTION

record type code major account number sub account number

If record type code is '10' then account header:

COLUMNS FOR:-IAT DESCRIPTION ===== ===--========

09-09 10-10 11-20 21-60

character character character character

total level code sign for account line number for fin. stmts. account description

If record type code is '20' then monthly transaction:

COLUMNS FORMAT

09-14 packed num 15-19 character 20-25 character 26-27 character 28-57 character

DESCRIPTION

transaction amount transaction number tansaction date (YYMMDD) journal posted from transaction description

If record type code is '30' then history record:

COLUMNS FORMAT

09-14 15-92

character packed num

DESCRIPTION

date last posted (YYMHDD) amounts for 13 months

Figure 1. Record Layout for Trial Balance File.

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.

491

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.

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).

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.

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.

Moveable identified The id

equipment within a by a number attached number was used to

company to each

identify

was item.

the

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.

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'

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:

convert 1238 to '001238': I D"LEFT( PUT (I DNUM, Z6,));

convert '1238' to '001238': ID"LEFT(PUT( I NPUT( I D,6,), Z6,));

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,

ANALYZING DATA

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.

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

492

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 non­SAS 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.

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:

PROC UNIVARIATE PLOT; VAR Al·IOU~T;

RUN;

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:

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

a histogram of the values.

Figur'e 2 is an example of the output from the UNIVARIATE procedure. For this example, the auditor can verify:

that these 1600 items have a total balance of, S878,300

that most of the balances (9996) are less than $2,310

that the highest balance is $4,681 and the lowest is $6

that the distribution is exponential, because the mean and standard deviation are nearly equal 9

that there are several large values, because a positive kurtosis indicates that several values exists in the tails of the distribution 10

that these large values are positive, because a positive skewness indicates that more values exist to the right-side (or positive­side) of the mean 11

UNIVARIATE

VARIABLEo::A:iOUNT

~IO~lEl\TS

N 1600 SUe! \o;'GTS ~EAN 548.938 SD:! STD DEV 742.987 VARIA~CE

SKEW~ESS 2.58516 KCRTOSIS DSS 1364826356 ess el' 135.35 STD ~!EA\'

T:~!EAt.;o::O 29.353 PROB> ITI SG~ RAJ\K 640400 PRoB>ISI NlJ!-1 ,; 0 1600

QUANTILES(DEFo::4 )

1600 878300 552029

7.1-6937 882694550

18.5747 o 0001 0.0001

EXTREclES

100% ~jAX 4681 99% 3591.82 LOWEST HIGHEST 75% Q:3 669 95% 2310.4 4180 50% l1ED 245 90% 1382.7 4282 25% Ql 115 10% 76 4491

0% MIN 6 5~ 52 9 4579 l':~ 20.02 11 4681

RA~GE 4675 Q3-Q1 554 MODE 110

Figure 2. Sample Output from PROC GNIVARIATE.

493

UNIVARIATE

VARIABLEo::MlOUNT

HISTOGRAM

•• <

II 1 2 1 4 5 2

BOXPLOT

o I I I

S 14 D 16 12 14 25 15 26 41 74

158 154 272 717

+-----+ I + I *-----*

100+,t"i"~'H,;"""**'~i"':"i"d"Hrl""''<i'''"h'''~*i'i'"i,,,,''''''''*,'<,H,,',**,~i'i'"kI.-f"'< +-----+ -- - -+- - - -+- - - -+- - --+-- - -+- -- -+- - - -+- - - -+- - - -+- --,Ie MAY REPRESENT UP TO 15 COUNTS

Figure 2 (cant.). Sample Output from PROC UNIVARIATE.

VARIABLE=A~toUNT

4700+

I ! I I I I I I I I I I I I I I I I

I I I I

UNIVARIATE

NORt!AL PROBABILITY PLOT

+++ '.'**

+ ++

+++ i, +++

1 OO+,H""'h·,-,"_"""';',~,~,·,,,·.

+-- - -+- - - -+- - - -+- - •• +. - - -+- - --+_. - -+-~ - -+- - --+_ •• _+ -2 -1 0 +1 +2

Figure 2 (cant.). 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

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:

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. 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.

FREQUENCY

400 eoo 1200 1600 2000 2400 2eoo 3200 3600 4000 4400

AMOUNT MIOPOINT

Figure 3. Sample Output from PROC GCHART.

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,

494

the costs of doing so are usually prohibitive. Programs for statistical sampling can be found in most audit software packages. 12

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:

the sample result is objective and defensible

the sample size may be estimated objectively in advance

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. 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.

The programs in Appendix III for sampling and sample evaluation are

%RANDNUM numbers

%SAMPSIZE random sample

generates psuedo-random

determines sample size for

°6RANDSAMP - selects an unrestricted random sample

%SYSSAMP - systematic (or interval) sample selection

%MUSSAMP selects monetary-unit sample using cell selection

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.

REPORT WRITING

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

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.

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.

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:

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;

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, Inc.

Saln AnalySiS 10)' state I'I<lntl>ly Sale& 110 $1,ooOs)

JAIIUAllY FEBRUARY JUNE

salas 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 ,,, All Saln 14,281 15,489 15.901 16,120 13.961 '"' Indians Tyl''' or sal8

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 no ~entucky 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 ". '" Salas 15,305 14,093 15,501 15,616 13,424 '" Michigan Type or S'le

'"

495

6,656 7.717 9,206 7,509 6,964 no Credit 8,263 6,458 6,268 8.286 7,499 on

14.919 14.175 17.496 15,791 14.463 ." State. 59,525 51,245 65,960 62,429 57,566 2,630

Figure 4. Example Output from PRoe TABULATE.

OTHER AUDIT TASKS

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.

For example, some packages provide programs:

to produce confirmation letters

to print aging schedules

to print mortgage amortization "schedules

for project scheduling to plan the" audit

for trend analysis

to solve linear programming problems. 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.

Totel

SOle<

36,511

39,888

16,459

"1,0"7

35,907

76,954

35,375

39,264

74,639

38,230

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.

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 cross­reference 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.

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 time­sharing companies.

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.

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-the­blank 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.

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.

496

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

o Go to SAS Display Manager System T Tutorial on the Audit System S Go to IS?F/POF (SPF/POF) .~ if available X Exit

Figure 5. Sample SAS/AF Menu.

Enter an option nUmber/letter on the I ine above.

Command ===>

Extract from fi Ie:

Extract data from a non~SAS fi Ie

Data Set Name ===> II:saspl "~'============== Model Data Set =="'> &model_

Create SAS Data Set:

~~~a w~~~ r~ r~ r:~~e ~~~~ :sa sd I Ib' __ ,(",.~,~."~'~'T' '0;;;'" -"",.,,~.,,,.;;;,r;,--Data Set Name "'==> &sasdset

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.

Jump to Opt i on ===> lI:optnum

Press PF3/PF15 Or enter END on co~mand 'I ine to continue.

Figure 6. 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 or enter RIGHT on command I ine to view next s.creen. Press PF'10/Pf22 or enter LEFT on command I ine to return to previous screen. Press PF3/Pf15 or eneer ErfD on command I ine when finished with the information required.

--InpUt Data fleld~~ Name Start Informat Label Format

Figure 6 (cont.) Sample SAS/AF Fill-in-the-Blank Screen.

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.

SAS software has the features needed for most auditing applications, but an' auditor is required 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.

FOOTNOTES

1. Howard F. Stettler, Auditing Principles (Englewood Cliffs, N.J.: Prentice-Hall, Inc., 1977), p. 522.

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.

3. Institute of Internal Auditors, How to Acquire and Use Generalized Audit Software (Altamonte Springs, Florida: Institute of Internal Auditors, 1979), pp. 53-55.

4. Ibid.

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.

6. Ibid., p. 40.

7. Gordon B. Davis, Donald L. Adams, and Carol A. Schaller, Auditing and EDP, pp. 395-400.

8. I nstitute of Acquire and pp. 53-55.

Internal Auditors, How to Use Generalized Audit Software,

9. Maurice S. Newman, Financial Accounting Estimates Through Statistical Sampling by Computer (New York: John Wiley and Sons, 1976), p. 54.

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.

11. Ibid.

12. Institute of Acquire and pp. 53-55.

I nternal Auditors, How to Use Generalized Audit Software,

497

13. Herbert Arkin, Handb,ook of Sampling for Auditing and Accounting (New York: McGraw-Hili Book Company, 1984), pp. 9-12.

14. Institute of Acquire and pp. 53-55.

Internal Auditors, How to Use Generalized Audit Software,

15. Ibid.

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 Auditing and Accounting. New Book Company, 1984.

of Sampling for York: McGraw-Hili

Davis, Gordon B.; Adams, Donald L.; and Schaller, Carol A. Auditing and EDP. New York: American Institute of Certified Public Accountants, 1983.

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.

Institute of Internal Auditors. How to Acquire and Use Generalized Audit Software. Altamonte Springs, Florida: Institute of Internal Auditors, 1979.

Leslie, Donald A.; Teitlebaum, Albert D.; and Anderson, Rodney J. Dollar-unit Sampling: A Practical Guide for Auditors. Toronto, Canada: Copp Clark Pitman, 1979.

SAS Institute Inc. SAS Users Guide: Basics. Version 5 Edition. Cary, N.C.: SAS Institute Inc., 1985.

SAS Institute Inc. SAS/AF Users Guide. Version 5 Edition. Cary, N.C.: SAS Institute Inc., 1985.

SAS Institute Inc. SAS/FSP Users Guide. Version 5 Edition. Cary, N.C.: SAS Institute Inc., 1985.

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.

Stettler, Englewood 1977.

Howard Cliffs,

F. Auditing Principles. N.J. : Prentice-Hall, Inc.,

Wallace, Wanda A. Handbook Accounting Controls. Englewood Prentice-Hall, Inc., 1984.

of Internal Cliffs, N.J.:

Wilburn, Arthur J. Practical Statistical Sampling for Auditors. New York: Marcel Dekker, Inc., 1984.

APPENDIX I. Descriptions

Using SAS Macros for File

It is recommended that file descriptions for non­SAS 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.

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:

in TSO: SAS AUTOS('''your.library.name''') with batch JCL: II EXEC SAS,AUTOS=·your.library.name'

Recall from the Extracting Data section of this paper the example that used a macro for the file description. Here is that program again:

DATA; %ACCTBAL; IF TRDATE='31JAN86'Dj

PROC PRINT; RUN;

The macro 90ACCTBAL 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. @11 RPTLINE SID. 021 DESeRTP $40.;

IF RECTYPE~120r THEN INPeT @9 TRA~IT PD6.

@15 TRNU~l $5. C!20 TRDATE YY:·j~lDD.

(c26 TRJOIJR 52. ~28 TROESe 530.;

IF RECTYPE~13Q' THEK INPUT @9 HRDATE YYMNDD.

@15 (HRAMTl-HRAMTl3) (PD6.); ~~NEND ACCTBAL;

The statements in the macro are substituted in the program wherever the macro name is used. Note that this macro allows for a parameter, DDN= I to be specified when it is used. J n the example the parameter was not specified so the default value for DON, ACCTBAL, was used.

498

APPENDIX II. SAS Programs for Checking and Transforming Data

%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'~' to the number will be more efficient than this macro. ;, .. ,,"1 I''';''' '''''*1 I,H,,", I:.;PUT, SAS data set that has been sorted. If it is *"''''/ 1**'" has not been sorted, the program will stop '-";<>"1 1*** after 10 out-of-sequence errors have been met. ,.**/ I*"i."""i: *""*1 I,"rlr{/ Ot .... TPl.:T: Either a SAS data set or a printed report of

the items that have been skipped .. *>,*/ ***1 ,,**/

I,rm', 1''** I''''':'';' ,,:-:.,,,/ I**" USAGE: %SEQCHK(IN=, ***/

***/ 1**" I,"',H, I,,,H, /-* 1"** where 1;''''* 1'>** I*'~" 1"*'" 1''''''* I'"'''' /**,. /*,,,,,, 1*>'* 1;'*" I~'*'":

OUT=, VAR=, PATTERN=) j

**"1'1 **""1 *'",-{'I

IN= 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

-/ I"''''';' EXAl'lPLE: 1*'":-,":

%SEQCHK( IN=SEQDATA, OUT=SEQERR, VAR=PARTItm PATTERN='CGSNN') j

"'**1 **""/ -{'**I 1''''"'*

1'''"'* 1**"" /,"'*""

-{,**/ ***1 *;""/

I"""'" 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) j

DATA &OUTj LENGTH PATTERN PREVIOUS CURRENT $ &STRLEN j RETAIN PATTER:-i &PATTERN; RETAIN PREVIOCS &PATTER!'; RETAI~ CSTR~C 'ABCDEFGHIJKU1~OPQRSTUWXYZ'; RETAI~ GSTICSL '0123456789ABCDEFGHIJKL1-lNOPQRSTUVWXYZ' j

RETAr:.; CSTR_NH 'ABCDEFGHIJKLl'lNOPQRSTUVWXYZ0123456789' j

RETAIN CS1"R-N '0123456789'; RETAIN SEQC:-''T 0; LENGTH. PAT_GRR STILGRR S 1; LENGTH 1-lSG $ 25; KEEP MSG &VARj

SET &INj

GURRENT=UPGASE (&VAR) ;

IF _1'_ = 1 THEN DO; PATIERN=REVERSE (UPGASE (PATTERN» j pREVIOUS=CURRENT; RETURN;

END;

IF CURRENT=PREVIOUS THEN DO; MSG='*** DUPLICATE ITEM ,~,"'*'; &VAR=CURRENTj LINK PRTOUT; REruRNj

El\1};

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 ;

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 {tit>': I PAT_CHR=SUBSTR(PATTERN, 1,1);

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 ;

END;

SUBSTR(PREVIOUS, I, 1)=SUBSTR(C,STR_C, VAW, 1) ; CARRY=1 ; GOTO END_LOOP;

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

END;

VALU'"'VALU-I0; SUBSTR(PREVIOUS, I, l)=SUBSTR(CSTR_N, VALU, 1); CARRY=l; GOTO END_LOOP;

END;

499

1*1,," USE NUM LOW-CHAR HIGH COLLATE SEQ***/ 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;

E~D; 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;

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

%IF &OUT = _NULL.. ~~THEN ~~DO; /,'ri"" PRINT RESULTS *i,* I FILE LOG; PUT @9 ~ISG @39 &VAR;

".END;

%ELSE %DO; &VAR=PREVIOUS; OUTPUT;

%END;

RETURN; RUN;

%M_EXIT: %MEND SEQCHK;

1*'''* WRITE RESULTS TO DATA SE1'*** I

, ~. I

Test Program for %SEQCHK Macro

1**~~'~********'I,*********~*1,*******,""",*,;-i'*''ri'*',,****irl,****'': / I**" Test Program for Sequence Check Macro ,,:-:,,,:/ 1*** *'1'*1 Itt'...... SAS Ins'titute Inc. 1"h~1 /'h':*****,,':**"~"""':*'iri'~"Wrlt'h'rlr..'''''1'1,***'rirlt'h,,**'·'****,,:*,,:'iri'''''':*,':*,':'Irld,o/rl",':,"",':-{r.H, I

DATA SEQDATA j INPUT @l PARTNUH $5. j

CARDS; AA-90 AA-91 AA-Sil AA-92 AA-96 AA-94 AA-98 AB-13 AB-14 AD-IS

RUN;

~SEQCHK(IN=SEQDATA, VAR=PARTNU~I, PAITER!>;:' CCSNN ') ;

Sample Output from %SEQCHK Macro

253 254 255 256 257 258

1**'''**''driri:**",*'iriri''Wrl'',,********'i.-<rI.:*>''*''''~'I'<fri''''',*,':**,h'''hh'rl:****;ri'f""'''***'':*1

/" .. ,** Test Program for Sequence Check Macro 1<>'0,/ If,,·,* ""'ric /

/*,'0': SAS Institute Inc. ,b",'1'1 I*,':***,'rlrl"':**'h':*,',{d'·."**,':**"i.-;"hh'rlt,b"''",;*,h',**,,:*,w,,·,,,**,,*:<,'"':irn,':,hhh',,"***,,,':i, I

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: nu: OAT" STATEl'lEST USED 0 . .50 SECOXDS AND 8401::.

272

THE CmlPILE PHASE (SED 0.47 SECm-mS. THE EXECUTION PHASE USED 0.04 SECONDS.

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 *** ITEM MISSING **1, AA-99

*** ITE" MISSING *** AB-OO *'~* 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 THE COMPILE PHASE USED 0.48 SECONDS. THE EXECl.'TION PHASE USED 0.06 SECONDS.

972K.

275 ~.SEQCHK(IN=SEQDATA, VAR=PARTNilll,PATTERN='CCSNN');

500

%DUPCHK Macro

%MACRO OUPCHK (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 I'~'~* variables may be checked. All other variables are '~**I

I*i'~' simply output to the new data set. '-'**1 If""* ,':o{,,~ 1 IM,* I~PUT: A SAS data set that has been sorted. ""w'l I*'~o{' ,~** 1 If,of,;, OL'TPCT: A SAS data set of the items that have been ,':M'I /,",,".* duplicated. """"1 I,h";' ,·,;n"1 I*'''~' VSAGE: ~~DUPCHK(IS=, ''''''*1 1"1" .... ' OUT=, *~,* I l"i"'''~ VARLST:::); ***1 1*''<" *r.I'l I;;·'~* where IN= SAS data set for input, if *,w'l 1*** ommitted then _LAST~ used. '''''*! I*~"~ OU1'== SAS data set for output (opt). -{'**I 1*"'* VARLST= name of variable or variables ***1 1*""" to be checked, Separate each ***! I*'~* variable name with a space. ***! I**":; Up to 10 names may be used. ***1 1*** "'** / li'** EXA.'1PLE: %J)tJPCHK(IN=DlJPDATA, ***! I*'~* OU1'==OUPERR, *,',,~ I I*",m VARLST=ACCOUNT TRDATE AMOUNT); *"'*1 1*** ***! 1**'" *"'*1 I**'t SAS Institute Inc. ***1 1**'~"Irk'"n."'~of<'''''"i'''rlri'''r*"**,·,****'~***_''"n.w,***,",**,,,**,,,***',,*'h''**'''*******"1,* I

%IF &VARLST "" . %THEN ~;.oO;

%PUT %STR(ERROR: VARIABLE NAt1E(S) ARE REQUIRED); %GOTO rLEXIT;

%END;

1*"* INITIALIZE MACRO VARIABLES "1.-'-""1 %LET VNAl-!ES~UPCASE(&VARLST); %DO 1=1 %TO 10;

%LET VAR&I=$t1ISSING~; %ENO; ":OLET VARCNT=O;

1"'*" EXTRACT VARIABLE NA~!ES FROH ~ACRO VARIABLE VAR O{,.,·,"I'I ~O 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;

%EXILOO:

/,h'''~ GET INFO ON VARIABLES 'h~*!

PROC CONTE~TS DATA=&IN OUT=DVPCHKC MEHTYPE=DATA NOPRINT; RUN;

I,"rl:,': Pl.'T LENGTH AND TYPE FOR EACH VARIABLE ''rlt'~1

DATA _NULL..... SET DUPCHKC; LE;>';GTH VNA:·IES S 100; V:\A~!ES '" UPCASE(tI&VARLST tI ); 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; 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!;

!**,~ 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

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

1*,',1. FIRST RECORD SET~UP M''''I IF REC_NL11=1 THEN DO;

LINK SAVLRTN; RETURN;

E~D;

/'"'"" 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 **"1

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 -:"""1 SAVE_RTN;

%DO 1'=1 %TO &VARC/>O'T; DC_HLD&I '" &&VAR&I;

%E~Di RETURN;

RUN;

%~EXIT:

%MEND DUPCHK i

Test PRogram for %DUPCHK Macro

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

@7 TRDATE ~~ 13 It\'VNU>1 @18 It\"VA'IT @25 NOTES

$6. yy:·It-IDD. 5\ .

CARDS; 111111860121L190 11510 111222860121L19021520 111333860121L19031530 111333860121L19031530 111444860121L19041540 111555860121L19051550 111666860121L19061560 111666860121L19061560

RUN;

7.2 $20. ;

RECORD 1 RECORO 2 RECORO 3 RECORD 3 DUPLICATE RECORD 4 RECORD 5 RECORD 6 RECORD 6 DUPLICATE

%DUPCHK( IN=OUPOATA, OUT=DUPFILE, VARLST=ACCOUNT TRDATE INVNUM);

PROC PRINT; RUN;

Sample Output from %DUPCHK Macro

OBS ACCOUNT TRDATE INV"'UM INVAMT NOTES

111333 9517 L1903 15.3 RECORD 111333 9517 L1903 15.3 RECORD 3 DUPLICATE

3. 111666 9517 L1906 15.6 RECORD 6 111666 95li L1'.106 15.6 RECORD 6 DUPLICATE

501

RECODE Program

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.

PROC FORHAT; VALUE GROUPF Lov,r-100 ='<= 100' 101-200 ='101~200' 201-300 ='201-300' 301-400 ='301-400' 401-500 ='401-500' SOl-HIGH='SOl =>';

DATA NUMBERS; DO 1=1 TO 1000;

MIOUNT=ROUND( (UNIFORH(0)"600) ,1); OUTPUT;

END; RUN; PROC FREQ;

TABLES AMOUNT / LIST; FaRHAT AMOUNT GROUPF.;

RUN.

RECODE Program Output

A~OVST FREQUE~CY

<= 100 162 101-200 161 201-300 179 301-400 156 401-500 164 501 178

CUMULATIVE PERCE~T FREQUE~CY

16.2 162 16.1 323 1i .9 502 15.6 658 16.4 822 17.8 1000

CUMULATIVE PERCEr..'T

16.2 32,3 50.2 65.8 82.2

100.0

:". ,

RECODE1 Program

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 output has been printed with PROC TABULATE.

FROG FORt-jAT; VALUE GROUPF LOW-IOO ='<= 100' 101-200 ='101-200' 201-300 ='201-300' 301-400 ='301-400' 401-500 ='401-500' SOl-HIGH='SOl =>';

DATA NUHBERS; DO 1=1 TO 1000;

AMmJNT=RDUND( (UNIFORMeD )"<600) , 1) ; GROUP=PUT(MIOUNT ,GROUPF.); OliTPUT;

END; RUN; FROG TABULATE; CLASS GROUP;

VAR ANO\J:-lT; TABLES GROUP ALL= 'TOTAL , , AMOU~~ eN=' COUNT' "';F=6. 0

SUM>'·F=COMMAIO. MEAN=' AVERAGE AMOUNT 1-·~F=COMHAI0. 2 5TD=' STANDARD DEVIATION''''''F=COMMAIO. 2);

RUN;

RECODE1 Program Output

I A~-lOUNT I 1- ----- --- ---------------- ----------- ---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 1 1601 24,6431 154.021 29.481 I -- - - - - - - - - - - - - - - -+- - - - - -+- - - - - - - - - -+- - - - - - - - - -+- - - - - - - - --I 1201-300 I 1861 46,8091 251.661 30.671 1- - - - - - - - - - - - - - - --+- - - - - -+- - - - - - - - - -+- - - - - - - - - -+- - - - - - - - --I 1301-400 I 1571 55,3051 352.261 28.371 1- - -- -- --- - - - - - ---+------+---- -- - - --+----------+----------1 1401-500 I 1631 74,3121 450.381 27.941 I - - - - - - - - - - - - - - - - -+- - - - - -+- - - - - - - - - -+- - - - - - - - - -+- - - - - - - - - - I 1501 => I 1621 89,8021 554.331 27.561 I -- - - - - - - - - - - - - - - -+- - - - - -+- - - - - - - - - -+- - - - - - - - - -+- - - - - - - - - - I I TOTAL I 10001 299,3531 299.351 173.121

502

APPENDIX III. Sampling Programs

%RANDNUM Macro

%MACRO RANDNUM (OuT"'RANDNl::1, START"'l, STOP"'. ,:-';(J~lBER=. ,SEED"'O, VAR=RANDNtN, REPLACE"'SO. Fr..:NCTION",r.;:\IFOR~!) ;

tl,-/"·,**'"""~i"'''''*,·,,.,''''·'id,,'',''''·,,,,'·:,,·,*,·,-: .. ;,,'**,'''.,'"-,.",."",,,,:,'d"''';,,'''·'''·''*·;'''''';'';''''''''''>i,,'' ,,",'<>'''''*1 I"'i'''' Random Number ~lacro - will generate 11 list of random *~""I

,.,,.,'1'1 ;-; .. "" (normal) numbers. Optional parameters are alloo.ed /,." ... ,-, for start. and stop so that a range may be specified. """I

;""'''1 -In'''''1 *""':1 *"*1 *>""1 -1'*'''1 f'**1 -:"'*1 ;""*1 ***1 *-1'*1 **"1'1 '''**1

/,'"",-, i"" ...... /"",', 1*'''' Pi"""", I''rlr>', I~

i"""* I"i"., (-I"'''~

(-I""''' I-I"b'<

1*';'* 1-/,*-1,

I""" /*.;:* I""~* 1*'''* I'h~* l,hH,

1''** 1"** 1**-;' I*"~""

r"';'" 1-;'-1<"1, (-I"""" 1,·,-1"' .. Ii"". ji""o,

ji"'''''' ji"'"'' /'"." /,,,<,,, 1""':", Ii"""

It\Pl'T:

OUTPUT:

USAGE:

none.

A SAS data set containing the numbers.

%RANDNUM(Ol'T=, START=, STOP=, NUrJBER=, VAR=, REPLACE=, SEED=, Fl'NCTIO:\'"") ;

where OUT'"

START=

STOp: t.;mlBER= VAR=

REPLACE=

SEED:o

'~*"I SAS data set name for output '~*"I

(default=RA~NUM) ''''''''1 Starting or lowest number **"'1 (default:1) *""'1 Stopping or highest number -1.1'-;'1 Number of random numbers made *"""/ Variable name for random *"""/ numbers (default=RANDNU~!) *'>*/ Specifies replacement. **'':1 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'*,~/

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 1*** RANUNI or UNIFORM. i,.,,,,/

;'*'''1 .,,,.,*/ ;,,'''''1 '~'~*I *'h~1

1*** /*** EXAMPLE: %RANDNUM(NUMBER=75 ,STOP=2000); I'~*''<

1**'" /*.,,,~ SAS Institute Inc. /*;'**,':*"I",:,·.1.,."· .. *****,hH<>H,,'''',-,, ,,',*"I,,'<>h,,*,"'H'i,*,H,'I,,"''''''*'''''''**>'*''**'''*' ,'"'",, ,' .. *,'''''1

%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;

~.IF ~;UPCASE(&REPLACE) = YES ~THEN ·000; DATA &O(';T;

KEEP &VAR _SAI1PID;

RUN; %END;

1**'': CHECK RANGE BETw"EEN START=&.START; IF START = STOP=&'STOP; IF STOP RANGE"'STOP - START;

START AND STOP -;,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) + START; _SAHPID+l; OUTPUT;

END; END;

ELSE DO; FILE LOG; PUT 'ERROR: INVALID RANGE'

START=' START I STOP=' STOP;

END;

%IF '::oUPCASE(&REPLACE} '" ~O %THEN ~DO; DATA &OUT;

RUN; %END;

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; N=N~l;

ENO; END;

IF RA~GE < 1 OR RA.'\GE < &t'lC~IBER THEN DO; FILE LOG; PUT 'ERROR:

END;

It-.'VALID RA~GE' START"" START I STOP=' STOP;

%l'LEXIT: %MEND R/u'lDNllM;

%SAMPS I ZE Macro

%MACRO SAI1PSIZE CIN=_LAST_,VAR=. ,TYPE"'. ,PRECISN=. ,POPSIZE::., CONFID=. ,EXPERR=.);

1'~"Im,:·,~~.."...,~**,h"''<>'ri,,·,...,:·,~~"-/:,H"**'",**i'i'i,*·ld''h'<>'ri'**".~,":**,":h'<**"l"":,",**,":,";ici,,',* "',,',,,<>', I Ihh' Sample Size Macro ~ will calculate sample size for 1'~'*1 1*'":'': unrestricted random sample for either attribute or *''''":1 I**" variable testing. ,,<>·,,"1 li,-/ri, "':**1 1*''<';' INPUT: SAS data set if TYPE=VARIABLE i""'*1 I*'~'" *,""1 I'''''C':, OUTPL:T: Sets macro variable SA~IPSIZE and prints il: ,'riti'l I",.;", on log. ,',*"" I 1*''''' *~-*/ 1*""': VSAGE: -:'SM1PSIZE (1:\=, "/",-:, / 1'"'*'" VAR=, '\":""'1 1*'":(' TYPE=, i,I""" I 1'".",: PRECISN=, *'''*1 l'i':-f'* POPSIZE=, mh",/ 1*** CONFID=, ,':-I:-!, I 1*'''* EXPERR=); ***/ 1*** *'":'':1 1*** where IN= SAS data set name for input, **'":1 /''''';'-:' required if TYPE::::VARIABLE. irlri'l /*1'* VAR= Variable to be estimated, *,"<*/ 1''''''": required if TYPE=VARIABLE. *"I"~I 1*** TYPE:::: Type of testing: code as '''*;<1 1*** ATIRIBUTE or VARIABLE ***/ I*''''~ PRECISN= Sampling precision or error. ***1 1""*'" POPSIZE= Estimated population size. ***1 1''** CONFID= Confidence limits. ***1 1**" EXPERR= Expected. error rate. ***/ 1*''''* **'":1 1*'*''< EXA~IPLE: %SM!PSIZECPRECIS~=2,CONFID=9S,POPSIZE=9000, ***1 1'':** EXPERR=l, TYPE=ATIRIBUTE); ***1 1*'":* **'~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;

503

DATA _NULL-; COt.:FID::::&CO;';TID; IF CONFID > THEN COl\FID-CONFIDI 100; CO~FID=PROBlT((1~CONFID}/2) ; 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;

%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;

%LET SIZE=50;

IWI,,": GET DATA SET SIZE '''"'''''1 DATA _NULL-;'

X+l; SET &IN POI1'<'T=X NOBS=~.iOBS; CALL SnIPUT('NOBS' ,NOBS); STOP;

RUN;

%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;

1*** DRAW SAMPLE ***1 DATA SSIZEj

1****-I:-!",m,,,,,,,,·.':'~~"":"'**":i:i""<*-I,**"";"-:'**-I""*",rI'i'**",,**,,,,'rlt,"'''"Im I 1,"<'Irl: From "SAS Views: SAS Processing" **"/ I"'*" 1983 edition, SAS Institute, p. 272 *,b':l l'h'<'·<*;"·<*-{".,..;..-::*I:-i,.;,......:,,Ht"/t,',.;,·"I,·.":,"'*,',,"drlt;,***,"*irl:,'rlt;,,"*"r.WrI,~, I

KEEP &.VAR; RETAIl\ K N; SET &I:O'j

K=&SIZE; N::::&NOBS;

PROB::::K/Nj IF UNIFOR~I(O) < PROB THEN DO;

_SMIPID+lj OUTPu'Tj K=K~I;

END; N=N-lj

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( %PUT %STR( ':'~PUT ':'~STR ( ;;;P{;T ~~STR( %PUT ~oSTRC \Pl;'T ~STR(

***;'*"i,<{""<*f",<*,':**"Irl'*"lrl,****,,,***,,<**,,,**,'rlrl<*,",****,,,.,***) ; *",,: PRECISN::::&PRECISN); *** POPSIZE::::&POPSIZE); *** CONFID=&CONFID); .,,*1, STDDEV::::&STDDEV);

SAMPSIZE=&SAMPSIZE) ; %GOTO ILEXIT;

tEND;

%M_EXIT: %MEND SAMPSIZE;

%RANDSAMP 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 -"""-'1 1m',," a SAS data without replacement. ""~"'I ;**,,, ""',1'1 r''i''~ It.:PUT: A SAS data set. """"'1 I"""" i<"ld,/ /"";,,~ OCTPG'T: A SAS data set. -I,M,! J'id,* ,',,'d: I I'"'''' USAGE: ~~RA;';DSA:!P (Ii\'''' , ,',-:,,'c / I"""'" OCT=, **;'1 r"·'··· SIZE=, ,h"*/ I'~""" SEED=); ,h,*/ /i<>"" ;",'rl'j

/'''''''' where IN"" SAS data set name for input *'~/ I,e"."" (default"'_LAST_l 1<-/":'1 1,,<*1, OUT= SAS data set name for output -:"'''''1 1,-":<"1, (default=RANDSAMP) "1''''''''1 1*"" SIZE=: Sample size desired. *"'*1 1*""" SEED'" Specifies the number that is ''<>'''*1 1''''''': used as the seed to the ,'<>"*1 /"." .. " random number function. It ''''-'':'1 1*'''''' should be 0 or a five·, six-, *'-":'1 r"h'.- or seven-digit odd integer. *"'-:'1 1'':-;'" If SEED"'O (default), then the 'i.-;,,"I I,n,* computer clock will determine 'Irl""1 I,"rlri, seed. '1,;';'1 1''<'''* ''''''''1 1*''<>' EXM1PLE: %RANDSAMP(IN=ACCTBAL,SIZE=100); ,·,·HI 1*''<>'' *'':*1 1*'·"', SAS Ins t i tute Inc. ''<>':*1 1**'":'-":'·I<1"·"',,'<>·,~"':'-":d"'<**"I'~"~*","h·'*'"·'*,'''·'''''':*'''~*'I"':'-":"·"''''rl:"l:<''''*,"rl''''''''*'':'-'':''b''·''''**'i.·1

i.IF &SIZE = %THE~ %DO; ~;PUT %STR(ERROR: SA~PLE SIZE IS REQUIRED); ~~PUT %STR( SIZE;&SIZE); %GOTO tLEXIT;

%END;

rrl"" GET DATA SET SIZE ''<*''1 DATA _NULL_;

X+l; SET &.IN POI!>.l'=X NOBS=NOBS; CALL SY:1PUT( 'NOBS' ,~OBS); STOP;

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;

1.1"", DRAW SA:1PLE "'''''1 DATA &.OUT;

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 ~;

SET &IN;

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 ;

RUN;

%!'lJ:XIT: %I'1END RANDSAMP;

504

%SYSSAMP Macro

%:1ACRO SYSSAMP (IN'" _LAST_, OUT"'SYSSAHP, I~TERVAL"'. START=RA~DO:1 ,SEED"'O);

/ ,,,.:,,',,,* "'""'h' .. ,.""',,,,.., ... ,,' .. *,~*,'·{".,',,..h"ic-:,-.'.-,"h·"" "',.;,.; .. ,'<>",-1,,'0',,,,* ,,':i,'I<"I, ,,.,,',,,:,',,",-1,,,, ''''', .. ',,'''';'''.,/ I''''··' Systematic Sample Macro - will systematically select """/ I records from a SAS data set. This is also referred """-;'1

to as interval sample. random if desired.

Starting record can be

I:';PCT:

Ol;TP!.:T:

l'SAGE:

SAS data set

SAS a<1ta set.

";SYSSMIP (I~=,

OUT"', ITIERVAL"', START= , SEED=) ;

""':"1 "n',,"1 '":*";'1 ''''''-;'-1 i,-I,,', / ''';''''/ "''1,,''/

;,"'1

"""I 'b'd'i ,""d'i ,"'",-1'1 *'1""1

where IN= SAS data set name for input -IH"'I

1*'':'" ji';"" 1"""* I'''''' 1"·"", I'·'·!.-I, I'''''''''' I''''''·'· I''';'''' I,,,,b': I''''"" ji'''''''' I,h"* I""""" I"",,"

OUT'"

I~TERVA1='

START=

SEEIF-

(default=_LAST_). ""'''''1 SAS data set name for output ''''''''I (default=SYSSAMP). ,d,," I Interval bet ... 'e€m records -}""*I selected. '1,,':'1'1 Specify starting record number or RA~DOli.

*,"'1'1 *'-":'1

Specifies the number that is ,,,,w'l used as the seed to the ,,,,h"1 random number function. It ,"m"1 should be 0 or a five-, six-, '''''''1 or seven-digit odd integer. *,""/ If SEED=O (default), then the *"'''":1 computer clock will determine '1:"1:'''1 seed. **,,/

l,h"'I, EXA~!PLE:

ji"','I, ~;SYSSAHP (1;';=ACCTBAL, INTERVAL"'lOO) ;

'1''1,'''; '1,,':'1<1 "'''''i'l

/*"1'.;' SAS Institute Inc. '''''ri'l .;"'"'"'"',,,,.;,,',,,,,',,','1 . .,·:.-,h,,·drl:, ,'"h'<'I"':-;,-I,,',,'d,,',-I,'I,*id,,',,,<* I

%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;

%IF %INDEX(%UPCASE(&START) ,R) %THEN ~WO; RECNU:-t= INT (UN IFOR.-'1 (&SEED) ''<& INTERVAL) ;

%END; %ELSE %00;

RECi-lUM=&START; %END;

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;

%rLEXIT: %I1END SYSSAMP;

%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 1"';:"1: If cell width is not given, it will be calculated. ''''~'I'I 1,'Hd, Records are selected according to cell selection method. ,"'h"1 I,"rl,,', Items that exceed the cell width are automatically ,-":d'i I'''''''' selected for 100% testing. These item~ t.;ill not be used ''''''''1 1'''''-;' in cell selection calculations. These large items will ''''''''1 /",,',.;, have _SM1PID=99999. """*1 ;-;,.:,.:, '':'''i'l Ii",,', 1*"'''''' /'''''' /',""

I!'{PUT:

OGTPUT:

SAS

SAS

data set. ,·,,'<'1'1 ,"*,'cl

da-.::a set. **'':1 "**1

/*',.;, USAGE; %MUSSAMP(IN=, *"/,*/ /*~, OUT"', ***/ r,i .. ,;- V AR= , *,,* / /*'1,," MATERL"', *,',* / /,,,*,, EXPERR"', **," / /*,..,., CONFID=, ***/ /'ic""': CELLI.nDT=); i'i",,/ /**'" ,,,**/ f'i""* where IN= SAS data set for input, if ,'<>H,/ /*',* olIunitted then _LAST_ used. ***/ /"<>'<1, OlJT::= SAS data set for outpUt. ***/ 1**'1, VAR= Numeric variable to be sampled.··>**/ /,'riri' MATERL= tlateriality. -Id-l:/

/,h,* EXPERR= Expected errors. *,'<1</ /1,-1",: CONFID= Confidence limits desired, *.,,,"/ /'''** CELLIriIDT=Cell width if you do not want ,'rlrit/ /i"""~- the macro to calcUlate it. *''*/ /-Irl'* *-1,,"/ /,.".,.:, EXA.'1PLE: ~:1C'SSA!1P(It-;=II>,'VDATA, ***/ r""" VAR"'M!OUNT, *'''*1 I~"" MATERL=20000, 1,-1'"7/ /".~. EXPERR=lO, *,'<1,/ /*"'* CONFID=95); i",," / /'''''''' *** / 1,·,'1,"1, SAS Institute Inc. '~**I

li"",*,,,*''''"ri'*'~~·*'irl<**,w.·i',,,*''·'''''''''****''''''*''<1'****''''''***'''*';,**",,,..;,.,,*,'rlrit'':,'<1<,':>'rid<>'< / ~IF &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;

DATA &OUT;

/"r{,,) TEMPORARY Al\'D NEw' FIELD SET UP .. '''''*/ RETAIN HATERIAL /'1,*,', tlATERIALITY **"/

EXPERROR 1"'-::-;, EXPECTED NU~lBER OF ERRORS ,'d "'I CONFIDEN /M,,·, CONFIDEz.>CE ,H,i'/ UEL /""'''' UPPER ERROR LI:'HT FACTOR ':"~-i'l

CELL"'IDT t·,:<,,-, CELL wIDTH "'-"-'/ CELLW~lt:L 0 /"-,"--' CELL "'IDTH :lULTIPLE -,'''':''1 CG~ISELPT 0 I,H,{, CU:1GLATIVE SELECTION POli-l! <,-:d,/ PCU~ISEL 0 1*";' PREV CU~1ULATIVE SELECT PT '1""'1 cm!SUBT 0; /,H,;, CmlULATIVE SUBTOTAL *"'*1

IF ~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: 1*1,-{, FIND NEXT SAMPLE SELECTION POINT ***/

/,',** GET RANDO~I NUMBER BETh'"EEN a AND CELL WIDTH **';'1 RA~1)NU~l=ROm-.'D (UNIFOR:1 (O),"CELLWIDT) ,1) ;

/'1,** CALCULATE CU~lULATIVE SELECTION POINTS *,"'*/ PCUC1SEL=CUtISELPT ; CUMSELPT""RAND~{;r! + (CELLWIDT * CELLWMUL);

I**""~ CALCULATE SAMPLING INTERVAL "'**1 SA~lPIt-."T=cmISELPT • PCUMSEL;

/**" 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

ADD_LOOP: 1*';-" ADD AHOliNT TO SUB UNTIL SUB IS POSITIVE **'':/ IF EOF THEN STOP;

SET &IN END=EOF; fi""* 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;

505

i'"'*'," ADD ISPL'T M!Ol.':"'T TO SUBTOTAL ,~*<,/

Cm!ST.:BT=CU~ISUBT + &VAR;

/-:,.:,,', GET ANOTHER RECORD IF SCBTOTAL STILL KEGAtIVE '1""\1 IF Cr.;~lSUBT -: a THE(>; GOTO ADD~LOOP;

/,H.-I, SCBTOTAL IS POSITIVE, OCTPCT RECORD FOR TESTI(>;G ,h', 'I i'""-"" -AND SELECT AGAI~ ,'n,;, /

SUB'LPOS:

SAflPt..;U~l+ 1; ~SAMPID=SAMPNUr!;

OUTPL'T; CELL"'MUL + 1; 1""* INCRE.'!ENT FOR NExT CELL 'I.-{'*/ GOTO NXLITE!1;

RUN;

%ILEXIT; %MEND HUSSM!P;

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 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.

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;

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 A TTR command can be used to link unlike variable

names together when the letter is being edited. Here is an example of how data is merged with a letter catalog:

PROG FSBROWSE LETTER=LTRLIB.LETTERS DATA=AUDLIB.ARAUDIT SEND=ARCONFRM;

RUN;

The confirmation Jetter would look like this before the data was added:

&&date' ______ _

&company ___________ c-_ &addrl ___________ __

&addr"2================_. &city~ &state_ &zip __

Dear Sir:

Our internal auditors are requesting that you verify the information in our files ,for your account.

Here are the details as we have them for your account:

ACCOUNT: &acctno' ______ _ BALANCE: &curbal ___ _

AS OF: &baldate __ _

If this information is nut correct, please make the necessary corrections, sign and return ~his letter. Thank you.

Sincerely,

Laura C. Stevens

%GPMLOAN Macro

%.'!ACRO GP~lLOAN (MiT=. ,APR=-. , YEARS=. ,FPDATE=., PLAN=. ,STEPS=. "STEPP"". );

li~' .. ,~"h",~,~''<*~,,''*,.'"',*,',*,"'*~,,',<,<,,''''<>H''*"/,i<i<*_t._.~"/,,~,""*,."",;-{"'"h.,*i«I,,"**-I,,"_t._.,,,,,",,-,.:,,'ri,,',,", I 1-::"'"/' Graduated Payment Mortgage Amortization Schedule ~Iacro *'''*1 l'fri';' >h"*l 1'" .... ,., This macro can be used to produce amortization ***1 I'''' ....... "' schedules for graduated payment loans. It assumes *-{,,"I I~ ... i~' that the term of the loan and the interest rate are *'''"'1 Ii""... fixed and that only the payment and the balance *'''''1 I''''''''''' change over the life of the loan. For fixed rate ''''''*1 1*'''"' mortgages, use PROC ~lORTGAGE. ''<**1 1'· ... '(.-";' **"/'1 1*"/<'1' USAGE: %LOANGPM(A:1T=, ***1 I'"'""'" APR=, ***1 1**'" YEARS=:, *,~* I 1*''<>'' FPDATE=, ,h'm I ji"''!:'i, PLA","', ***1 1'""':* STEPS=, **-1'1 I'"c":ri' STEPP=); ***1 1**';'

,'d,* I (1""" where AJIT amount of loan ''<**1 1*"* APR annual percentage rate *'':*1 1""'* YEARS number of years **""1'1 1*"'"/' FPDATE first payment data (opt) """"**1 1**"/' code as DDMMMYY **'~ I

506

1*"/"': PLAN FHA Plan number: "/ri"~1 1*'"'* code as FHAI ***1 1*'':* code as FHA2 *'''*1 1*''''' c;.ode as FHA3 '''''*1 1'''''<* code as FHA4 ''<**1 1'''*''''' code as FHAS ***1 I-M,';' STEPS number of payment steps ***1 1*'''"' STEPP percentage increase with each "/"'<>"1 /,~'""~ payment st.ep "" ... '1 t.,<·~;, ,h"" I I*'''* EXMlf'LE,: ~~LOA~GPH(A:1T=50000 ,APR=12, YEARS""30, ",,,*/ 1''<*';' PLAN""3,FPDATE=OlClAR86); ,;+",1. I"m''< **"/'1 1'''':* SAS Institute Inc. *"/,*! I*'':*';-{''''',<*' i~"h"""<"·,","","'"**'''''''i'''''"'<-Ici,*"/,,,,**,''''<*"/'"/''':iri,,'<>,<***,~,'''I'i''',, .. *****"/",<,"',,*"/,,~ I

~;IF &A:1T = OR &.APR "" OR &YEARS = OR (&PLA:-< '" A:';D (&STEPS = OR &STEPP "" .») %THEN ~DO;

~~PvT \STR(ERROR: 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;

%IF %UPCASE(&PLAN) = FHM ~·~THEN %00; %LET STEPS=5; %LET STEPP=O. 025;

%E~O; %IF ~-;UPCASE (&PLAN) ::: FHA2 %11IE;'; %00;

~LET STEPS=5; ~;LET STEPP~O.050; ~;E:-\D ;

%IF ~.l.'PCASEC&PLAN) = FHA3 'aHE~ %DO; %LET STEPS=5; %LET STEPP=0.075;

%END; %IF %UPCASE(&PLAN) = FHA4 %THEN 'JlO;

%LET STEPS=10; ~;LEr STEPP=O.020; %ENO;

%IF %UPCASE(&PLAN) "" FHA5 %THEN %DO; %LET STEPS=10; %LET STEPP=0.030;

%END;

OPTIONS LS=80; DATA LOAN;

LENGTH MIT 8 IRATE 8 PERIODS 8; A!1T=&MIT; 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=IRATE/12;

ELSE RATE=IRATEIl200 j 1*** CALCULATE PRESENT VALUE FACTORS ,~,w'l DO 1=1 TO N_STEPS;

PV=( 1 ~ «( 1 +RATE ),"rl, C ~ t~ C r,', 12)))) IRATE; END; I=N_STEPS+l; PV=( 1 ~ « l+RATE)"/'*( ~ l*PERIODS))) IRATE; 1=1; TEMP=PV; DO J=2 TO N_STEPS+l;

I=J; FINISH=PV; I=J~l; START=PV; TEMP=(FINISH ~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(PDATE),4 0); I\TEREST=PRIN_BALi'RATE ; PRI!CPD=PYm ~ 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;

END;

IF STEP _CNT <= LSTEPS THEN pnlT""PYl1T>'<P _STEP; STEP_CNT+l;

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 I I I @18 'A.'10UNT OF LOA..\". II @18 'HIGHEST LOA.-': BALA:\CE. I I @18 'ANI-."UAL PERCEI-."TAGE RATE. II @18 'PERIODIC RATE .......... . II @18 ':\l)}!BER OF PAY~lEl'<TS.

@45 AMT COMMA 15 @45 HIGH_BAL COM:1A.15 @55 IRATE 5.2 @51 RATE 9.8 @55 PERIODS 5.0

II @18 'TOTAL PAYMENTS. II @18 'TOTAL INTEREST. I I @22 '---~--- PAYME1>,"T DO 1=1 TO S_STEPS;

@45 TOLPYMT Cmll1A15 . . . . . . . . . .. @45 TOT_INT COM!1A15 SCHEDULE -------';

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 RUN; 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

~!oNTH="~MONTH' PYMT= ' *p A YM£NT '

INTEREST=' INTEREST'~PAID' PRIK_PD=' PRIl\CIPAL"'PAID'

PRI~CBAL='PRISCIPAL'~BALM';CE' ; RUN;

%~LEXIT:

%HEND GP:1LOAN;

%GPMLOAN(AHT=50000 ,APR=12, YEARS=30, FPDATE=O 1!1AR86, PLAN=FIiA3) j

%GPMLOAN Macro Output

LOAN SUMMARY

A.'10Ul'T OF LOAN.

HIGHEST LOA", BALA~CE.

• ...,"SUAL PERCEC\,AGE RATE.

PERIODIC RATE.

NUMBER OF PAYMENTS.

TOTAL PAYMENTS.

TOTAL INTEREST.

YEAR YEAR YEAR YEAR YEAR YEAR 6+

PAYMENT SCHEDULE

50,000.00

53,935.41

12.00

.01000000

3" 197,99792

141,99192

395.69 42.5.36 457.2.7 491.56 52.8.43 568.06

507

LOAN DETAIL

INTEREST PRI),;CIPAL PRINCIPAL YEAR ~O!\'TH PAYMENT PAID PAID BALANCE

1986 MAR 395 " 500.00 -104 . .31 50,104.31 APR 395 69 501.04 -105.36 50,209.5; MAY 395 69 502.10 -106.41 50,316.08

"'"' 395 " 503.16 -107.47 50,42.3.55 Jl.:L 395 69 504.24 -108.55 50,532.10 AUG 395 " 503.32 -109.63 50,641.73 SEP 395 " 506.42 -110.73 50,752.46 OCT 395 69 507.52 -111.84 50,864.30 ~ov 395 69 508.64 ~112.96 50,977.25 DEC 395 69 509.7i -114.08 51,091.34

-~------------- ----------- .. _- ---- -~ -~~~~~~--

1986 3,956 88 5,048.21 ·1,091 . .34

1987 "N 395 69 S>O 91 -115 " .51,206 " FEB 395 69 .512 "' -116 " 5 L, 322 "

Output compressed '0 save printing. ~lacro "'ill produce full Schedule.

2015 JAN 568 00 73 " 494. " 6,892 " Foe 568 00 88 " 499. 13 6,393 " MAR 568 06 " " 504. 13 5,889.44 APR 568 06 58 "' 509. n 5,380.28 MAY 568 06 53.80 514.26 4,866.02 JUN 568 06 48.66 519.40 4,346.62 ""L 568 06 43.47 524.59 3,822.02 AUG 568 06 38.22 529.84 3,292.18 5EP 568 06 32.92 5.35.14 2,757 04 OCT 368.06 27.57 .540.49 2.216 55 )-;OV 568.06 22.17 545.90 1,670 66

D" 368.06 16.71 531. 35 1,119 3D ----- ---~-~---- ---- -- -~~------ -~~~~----------2013 6,816 73 549. 14 6,267 . .59

2016 JAN 568 00 11 " 556.87 562.44 FEB 588 06 62 562.44 0.00

~-- ~- -- -------- ~--_.- -------~~ ~~ -- -----_ .. ---2016 1,1.36. " 16 82 1,119.30

-~-=

197,991.92 147,997 92 50,000.00

%XREF Macro

%MACRO XREF (PROCLIB=,OUT=XREF, SELECT=. ,SORT=.); I'~*'I;-I:*'~*H"'*'I"·"·,*,"""~'~'~'''~C"I"·,**,,,'''·C"I'·:''~"I'* :,,"**'·,,·,,;'[,,""';,[""'W"·""i,·:,~, I I'h,* Cross-reference ,'iactco - will print report and output *'-""1 1**'" data set of proc names and the programs used in the -:;-1:':'1 I'i."'~'" procs. It also lis"ts the non-temporary data set *';.['1 I'~"'~' tha"t are used in the procs (i.e. DSNs not containing ·:"H'I I'''-Irl' &&). This macro uses the SO(JRCE procedure in SAS *'~*I

I'~** software which is limited to 80~byte, card~image proc "Iri"~1

r'*'~ librarie~. This macro only works unde!' OS. *'1"·'1 1*'-"" *,H'I I,h"., ISPt.'T: An PROG or JeL par"ti"[:ioned data se"t libra.ry """'~I

I''''''~ thnt has SO-byte racords only. *""~I

I'~''''~ "':-I,..,~ I r"h" OUTPUT: A SAS data set and printed report of the procs *''*1 1*'''·' and programs that have been cros~-referenced. ***1 1''** ~,-{,* I 1'''** WORK: A temporary file that is used to store the -Irl""1 1**'" FILE unloaded library before the search takes place. **"'1 Im"* I f this macro is run in batch mode, "then a -:.**1 1,;.[,0{< temporary file must be allocated with the *'~*I

I,,-Iri< DDNANE of STHPLIB. *"**1 1*''* -"'~I I' ...... ."." USAGE: %:o.."REF{PROCLIB=, **1'1 11."'~* OUT::, ***1 I''''~'''~ SELEGT:. , ~d,," I I'~** SORT=.) j *,,'''1 I'·" .... " **"1 IH,* where PROCLIB= DDNAHE of PROC or JGL library ~"'*I I*,d, to cross~referenced. ***1 1*** OUT= SAS data set for output **"1 li'** SELEGT= List(5) of members to be **"·~I 1*",,·, searched. Review the SELECT ***1 I*~"~ s"tatement of PROC SOURCE for ~'*'''I

1''''',* proper coding of this parm. *'1'*1 I'~** SORT= Type of sorting requested for **'1'1 I~"'''~ report or output data set. *''''~I I*'''~ Enter PROG, PGH, or DSN in any *'~*I 1'"'** order ... ith a space between the -/d'*1 I'''-Irlt words. ***1 I*{'* *"*1

I~"~* EXMIPLE: I'm" 1';"'* 1",-;,,·,

%XREF (PROCLIB"'~IYLIB, SELECT=S: , SORT=:PROC PG~I DSN);

,,,H< 1 ''''''*1 ~/

*'#*1

I'"'''' I;"~' ,~,','h"·.,.;,·:,·."·" ,·;,·;,-.,,·;,·;,';"."';,·,'<'!d,;';'·;'·" '-;'·;"'rl

SAS Institute Inc. ;';""1 "",,,,,,,,,,.,;,,"'h·,,·"',,':;,, ,"'1"""""'''''''''''-;'1

%IF &PROCLIB:: OR &SELECT = . OR &SORT = %THEN %DO; %PUT %STR(ERROR; VARIABLES WITH MISSING VALUES ARE REQUIRED); %PUT %STR( ,"** PROCLIB=:&PROCLIB); %PUT %STR( SELECT=&SELECT); %PUT %STR( ,,:{,,,: SORT"'&SORT); %GOTO !LEXIT;

%END;

%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 DS:'<)

OR &&ORDER&I '" ·",THEN %[)O; %PL'T ':;.STR{ERROR: SORT PARA~!ETER IS NOT VALID); %PUT ~.5'rR( SORT--&SORT) ; %GOTO CLEXIT;

".END; %E~D;

I~d"" READ LIBRARY TO GHECK DSORG AND GET DSN FOR REPORT TITLE ''rl''''1 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;

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;

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;

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; END;

IF INDEX (A_REC,' PROC ') TIlEN DO; 1*1,,·, GET PROC NAtJE '''',,''1 PTR=3; DO WHILE (PTR<72);

CHR=SUBSTR(A_REC, PTR, 1) IF GHR NOT= ' , THEN DO

PROC=TRIM (PROC) II CHR PTR+1;

END; ELSE PTR=lOO;

END; END;

508

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;

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;

Dm; OUTPUT;

SKIPOCT: E~IJ;

RC~;

/,,""'" SORT A:\D PRI~l X-REF DATA "'{<-!'I TSO FREE F(ST~lPLIB);

PROG SORT DATk=&ODT Ol'T;¢OUT; RUN;

BY &ORDERI &ORDER2 &ORDER3 j

TITLE2 "GROSS-REFERE:';CE LIST TITLE3 "ORDER ="'> &SORT PROC PRINT DATA"'&.OUT SPLIT;'

FOR LIBRARY => &LIBDSN"; SELECT LIST => &SELECT"; , LABEL UNIFORM;

RUN;

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' ;

%tLEXIT: %:·IEND XREF;

Sample Output from %XREF Macro

CROSS-REFERE .... CE LIST FOR LIBRARY ==> SYS2.JOBPROD PROCLIB

PROC NAME

$S$$sm

$$$S$OX

$$$$$OX

$$$$SIX

ORDER ="'> PROG PGf! DSN SELECT LIST ==> $:

PROGRAM DATA NAME SET

t\MIE

FC0048 NO DATA SET NMIES FOR PROC

ZZZ1l8X 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 ALIAS FOR PROC MEMBER NAME IS ALIAS FOR PROC ME~IBER NAME IS ALIAS FOR PROC MEHBER NAME IS ALIAS FOR PROC MnlBER NMIE IS ALIAS FOR PROC MENBER NAME IS ALIAS FOR PROC

ZZZ1l8X SSS TAPECOPY LABELT SSS TAPECOPY LBLINFO

l1E}lBER OR

ALIAS

S$$$$Ml

$$$$$OX $$$$$OX $$$$$OX $$$$$OX $$$$$OX $$$$$OX $$$$SOX $$$$$OX $$$$$OX $$$$$OX $$$$$OX $S$$$OX $~$$$OX

$$$$$01 $$$$$02 $$$$$03 $S$$$04 $$$$$05 $$$$$06

$$$$$IX $S$$$lX