You are on page 1of 19

SAS

macro facility is a tool for text substitution. The SAS macro facility is a component of Base SAS. The two main components of the SAS macro facility are SAS macro variables and SAS macro programs.

The

programs you write can become reusable, shorter, and easier to follow. You can accomplish repetitive tasks quickly and efficiently. You can provide a more modular structure to your programs.

macro variable can be referenced anywhere in a SAS program other than in data lines. Macro variables can be used in open code as well as in macro programs. All values assigned to macro variables are considered text values. The name assigned to a macro variable must be a valid SAS name.

You

tell the macro processor to resolve a macro variable value by preceding the macro variable name with an ampersand (&). When referencing macro variables in a SAS statement, double quotation marks enclosing a string allow resolution of macro variable references while single quotation marks do not.

Automatic:

Built-in macro variables. The automatic variables listed depend on the SAS products installed at your site and on your operating system. Global: User-defined global macro variables. Local: User-defined local macro variables. Local macro variables are those defined in the currently executing macro program that have not been designated as global macro variables.

%let path = D:\Sanjay\SAS Material\SAS Practice Downloads\SAS Data ; libname practice "&path";

The

%PUT statement instructs the macro processor to write information to the SAS log.
%put _automatic_; %put _global_; %put The value of practice is &path;

With

SYMBOLGEN enabled, SAS presents the results of the resolution of macro variables in the SAS log. SYMBOLGEN displays the value of a macro variable in the SAS log near the statement with the macro variable reference.

options symbolgen;

SAS

automatically defines a set of macro variables when a SAS session starts. The macro processor maintains these variables and their values in the macro symbol table.

SYSDATE:

the character value that is equal to the date the SAS session started in DATE7. format. SYSDAY: text of the day of the week the SAS session started SYSLAST: name of the most recently created data set in one field: WORK.TEMP

One way to create and update a macro variable is with a %LET statement. Syntax:

%let macro-variable-name=macro-variable-value;

%let year = 98; proc print data = sasuser.stress&year; run; %let dataset = calves; title "Dataset: &dataset";
proc print data = practice.&dataset; run;

%MACRO program <(parameter-list)></option(s)>; <text> %MEND <program>;

macro program is executed by submitting a reference to the macro program. %program

where program is the name assigned to the macro program.

%macro printing(dataset); title "Dataset: &dataset"; proc print data = practice.&dataset; run; %mend; %printing(cars)

By

default, SAS language statements submitted from within a macro program are not written to the SAS log. To see the SAS code that the macro processor constructs and submits, MPRINT option should be enabled.

options mprint;

The

information written to the SAS log when MLOGIC is enabled includes :


the beginning and ending of the macro program the results of arithmetic and logical macro language operations.

The

MLOGIC option is useful for debugging macro language statements in macro programs.
options mlogic;

You might also like