11 March 2014

How to resolve common programming errors in SAS? A guide for Base SAS users

SAS provides a good interface for writing programming structures for analysis of data through windowing mode, that is, different windows for performing different tasks to a data, and this internally generates different SAS data sets; a SAS dataset is a special structured file, which is used to save the data in columns and rows. Apart from this, SAS also provides a good interface for generation of reports in the output window and for the generation of errors in the log window.

Like all other windows, log window is always active thought out the SAS session, and whenever data steps are compiled and executed there might be errors or warning messages generated during the compilation process of a programming code and these errors or warning messages are always displayed in the log window. Most of the error or warning messages are very easy to understand, but most of the first time users feel that these errors are hectic. The most common errors done by the amateur base SAS users are as follows:

Resolving the common errors:

When a basic program is written and run for compilation, there might be a lot of errors in the log window that are usually generated during the compilation process. Such errors usually are simple, for example a single error in the beginning of the program will not allow the rest of the program to be compiled. SAS compiles the program in steps, so the programmer has to verify the errors in a stepwise manner too. If the error is at the beginning of the program, which is not allowing the entire program to compile, one has to first resolve those errors so that the rest of the program can be compiled successfully.

When errors occur in the program, SAS underlines that statement in the log window and generates error message. Looking at the statements above and below the underlined error and by understanding the error message that is produced by the SAS log error message and correcting it might make the program run successfully. Most of the errors are caused by very common mistakes such as:

Missing semicolon: The common mistake among the basic users is missing semi colon (;) at the end of each statement in the SAS program. This may cause SAS to misinterpret not only that statement with missing semicolon but also the rest of the statements that are present.
SAS stops the compilation of the two or more statements and generates an error message in the SAS log.

Errors will be:
ERROR: Statement is not valid or it is used out of proper order.
ERROR: The option or parameter is not recognized.

For such kind of errors, identifying the underlined errors in the SAS log, and placing the semicolon at each statement may run the SAS programming steps successfully.

Data type errors: SAS reads character values and numeric values differently, the variable that contains numeric values are by default read by the SAS input buffer, where as character values are not read by default. Therefore in SAS, variable names that contain character values should always be followed by a dollar sign.

Most of the programmers have a perspective thinking that, the values are taken normally without producing a dollar sign to the character variable, but such variable values are read as numeric values, so values will not be taken. When such programs are compiled, only variable is assigned but with zero values, and SAS log generated a note message that,

NOTE: Invalid data at line

To resolve this error, the programmer has to just assign a dollar sign to that specific variable, so that the character values are assigned to that specific character variable.

Misspelling the Keywords / Statement / Symbols: Each and every keyword or statement should be spelled correctly in SAS, but sometimes due to poor writing skills of the programmer, some keywords or some statements are misspelled in the programming structure. But such kind of small mistakes are usually fixed by the SAS system itself, executing the result of the dataset. But in the SAS log a warning message will pop-up on the log window, however these warning messages will not interrupt the final outputs.

WARNING: Assuming the symbol DATA was misspelled as DAT.
WARNING: Assuming the Statement INPUT was misspelled as IPUT.

Even if the results are displayed correctly, programmer has to still go through the warning messages generated in the SAS log window that are generated during the compilation and execution of the program, and make the relevant changes to the program.

Conclusion: Thus, in SAS, a programmer has to check the log window for error messages and warnings, even if the output of the data set looks fine. Errors are usually generated due to simple mistakes made by novice SAS users who often forget to include the right symbol in the right place or make spelling mistakes in the program. Warnings and notes are equally important as errors messages. The programmer has to understand the log of a dataset as it helps him/her to avoid the same kind of errors in the future.

Clinnovo is a clinical innovation company. It is pioneer CRO industry in India. Clinnovo offers professional Clinical Research Course, Clinical Data Management Course, SAS and Imaging training. Clinnovo has been serving different bio-pharma industries across the world with excellence and high quality. For more information contact at +91 9912868928, 040 64635501.

No comments:

Post a Comment