Categories‎ > ‎

Code Generation

The following macro programs generate code. The macros copy the generated code to the clipboard for the user to paste into SAS code in the appropriate location. These processes help to write specific pieces of code in a standard manner, quickly and efficiently.

BlankFind

Generate code to find blank macro arguments. Useful as the first step in any macro program for required arguments.

CopyPath

Copy the path from a libref or fileref. Useful for quickly obtaining the path without going to the OS.

FormatList

Generate a list of variables to use in a FORMAT statement, including the variable format. This is useful to modify the format of a list of variables without changing the overall order of the variables, or to change the order of the variables without changing the formats (before the SET statement). For a list without formats, see the KeepList macro (below), and for SQL, see the Select macro (below),

KeepList

Generate a list of variables to insert into a KEEP statement, or any other statement that accepts a list of variables. For SQL, see the Select macro (below).

Select

Generate a list of variables for SQL, with commas in between the variable names. Optionally specify the prefix (e.g., a) to add to the variable (e.g., a.var1) for referencing the source table. This is useful when you want to select only some of the columns or to add columns in between other columns.

ValidArg

An expansion of the BlankFind macro that generates code to validate macro arguments based on various criteria, including looking for blanks, Y/N values, a list of valid values (e.g., DATA PROC), and whether the values are numeric or character.