Symbol Table Generator

Symbol Table Generator Jim Johnson, Principal Scientific Programmer Covance Periapproval Services Inc, Radnor, PA

ABSTRACT

Have you ever written a lengthy program, printed it, and tried to find where in the program that a particular variable or two were used? Do you remember sitting there with your printout, highlighter, and program editor, repeatedly using the editor's find feature, then trying to locate the reference in the printed copy so you can highlight it? Or, maybe instead of tediously looking for all the references, you simply used the editor's change feature and changed all occurrences of a variable to another spelling. Then when you ran the program you found that you had changed things that you did not expect like TITLE statements, data set names, or keywords.

This paper will present a short program that reads a userprovided SAS? program and generates a line numbered listing of the program and a symbol table, indicating each variable and keyword in the program and every line number on which it is referenced. The Symbol Table Generator excludes comment text (I know we all use ample comments in our codeJ). A few of program restrictions and limitations will be discussed, as well as a unique programming style.

PROGRAMMING STYLE

In general, SAS code only occupied half of the computer screen (exhibit 1). Occasionally there are lines that wander into the other half of the screen. Often they can conveniently be broken into two or more lines, sometimes making them even easier to understand.

Instead of allowing half of the screen to go unused, a ribbon of comments can be added down the right half of the screen using slash star ? star slash comments (exhibit 2). Then, within that ribbon of comments, meaningful, detailed comments can be inserted (exhibit 3). Using this method, one can easily see what a specific line or group of lines does. If more than the half screen comment line is necessary to get the point across, then simply use more lines as seen at the bottom of exhibit 3.

There are those programmers who like to use the slash star ? star slash comments to comment out blocks of code (exhibit 4). Unfortunately this technique does not work well with the comment ribbon. An attempt to block code this way will produce unexpected results because code other than you might expect will be commented (exhibit 5). An alternate method would be to use a column of asterisks down the front of the code to be commented (exhibit 6). This method, though a little more time consuming does more readily show the reader what has been commented. The slash star ? star slash method might not be as clear because the beginning or ending symbol may not be readily noticed by the reader.

This style of programming has its advantages and disadvantages. It takes some getting used to, but when you get accustomed to it, it can be a very valuable tool, and those who inherit your programs later will be thankful you used this technique.

data __len__; infile "& dsn" length=lg; input @; length=lg;

proc sql noprint; select max(length) into : lrecl from __ len__

; select compress(' $char' || put(min(&linesize-10,max(length)),8.) || '.') into : fmt from __ len__

; quit;

data __symb__(keep=symbol2 symbol line);

infile "& dsn" lrecl=&lrecl pad;

file print ll=ll notitle;

retain page

dt

asterisk

slashstr

num

text

line

0

delim

" {}[]!@#$^*()+-=\/|:;'?> ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download