12 April 2014

Solving Common Macro Programming Problems and Errors

In SAS, Macros is an additional facility in the program for extending and customizing SAS programming codes, whereby it reduces the amount of codes that are entered to do repeated common tasks during programming. While using macro-facility, programmers creates a macro name for repetition of common tasks and during programming these common repetitive tasks are called into SAS using their respective macro-names.

During creation of new macro variable names within the base SAS programming code or calling in already existing macro variable names into base SAS programming code, a programmer might face problems in compiling the code or managing errors during the process of using macro variable names in the code. Some of the common problems and errors are discussed below.

There are different stages in the macro-processing unit to process macros. Macro-errors are generated at each stage of compiling a macro-code; For example, macro-errors can be generated at these stages like,

Macro variable resolution
Macro open code processing
Macro compilation
Macro execution

If misspelling is done while typing a macro-function name or omitting a semicolon, it will generate syntax error during compilation process, which says that, the syntax written by the programmer does not confirm to the rules of the macro language. Or programmer might refer to a variable that is not  resolved during programming which leads to variable resolution error. During programming there could be execution errors or semantic errors too; these are usually generated when a macro-facility has faulty logic. That is, statements present in the macro-facility are not executed in the right order or in the right way that the programmer has expected.

During the macro code, sometimes the SAS windowing environment stops responding after the macro code is submitted for processing. The cause behind this may be missing of semicolon or parenthesis or quotation mark or macro end statement or this error can be from missing of unclosed comment during the programming. This type of errors can be solved by checking the program for any missing syntax and correcting them, so that the program can run successfully.

While compiling a macro in SAS environment, sometimes the macro will not compile correctly. If the macro is not compiling correctly during compilation process then there might be some syntax errors done during typing a macro code, to overcome this process, programmer has to identify and write the exact syntax to compile the macro. Only syntactically correct macros are compiled by SAS compiler.

Sometimes during the execution of macros in SAS, the execution process may get terminated in the middle. It might be due to non-standard values that are passed to a macro, for example a parameter. That is, there might be less number of parameters that are passed than required. Therefore, passing exact number of parameters will execute the macro successfully.

Solving common errors while macro generation:
Major problem arises when a new macro is created or calling already existing macro in SAS code, for example if a macro-name is created with a name “ XXXX ”, and it has certain values within that name, now programmer wants to repeatedly call those values into another program. So he/she need to call the same name each time.

If macro-name is misspelled when invoking a macro, that is if the macro-name is misspelled as “ XXX ” while invocating, then while compilation SAS generates an error message stating that “ Apparent symbolic reference “ XXX ” not resolved ” that is the macro-name “ XXX “ was not created and it cannot call any associated values.

The exact solution to overcome this process is to call the macro-name with the exact name or by developing bug free macro. Here is the explanation how to develop bug free macros

Bug free macros: What is bug free macro? How this is used? Macro is always a huge program written at once. While coding such programs at once, a programmer always performs errors, which makes the program unresponsive. Therefore, while writing the codes, it is advised that the programmer make their codes into small sections, such that each section of the code will contain macro-program, and each section is tested separately by compiling each section individually. If each section is compiled successfully, then placing all the sections together can make the complete program compile successfully. Such programs are commonly referred to as bug free macros.

Conclusion: Writing a Macros-facility will make the repetitive common tasks easier and at the same time the same macro-facility can be used for different datasets. But creating a macro is a huge process. Thus by understanding the different types of macro-errors that are generated, and knowing how to solve them, can make programming work easier and faster.

Clinnovo is a clinical innovation company. It is pioneer CRO industry in India. Clinnovo offers professional clinical research course , clinical data management course , SAS Courses 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