Previous Page | Next Page

The Structure of SCL Programs

Using Macros in SCL Programs

You can use the SAS macro facility to define macros and macro variables for your SCL program. That is, you can use SAS macros and SAS macro variables that have been defined elsewhere in the SAS session or in autocall libraries. You can then pass parameters between macros and the rest of your program. In addition, macros can be used by more than one program. However, macros can be more complicated to maintain than the original program segment because of the symbols and quoting that are required.

If a macro is used by more than one program, you must keep track of all the programs that use the macro so that you can recompile all of them each time the macro is updated. Because SCL is compiled (rather than interpreted like the SAS language), each SCL program that calls a macro must be recompiled whenever that macro is updated in order to update the program with the new macro code.

Macros and macro variables in SCL programs are resolved when you compile the SCL program, not when a user executes the application. However, you can use the SYMGET and SYMGETN functions to retrieve the value of a macro variable or to store a value in a macro variable at execution time, and you can use the SYMPUT and SYMPUTN functions to create a macro variable at execution time. For more information, see Using Macro Variables in SCL Programs.

Note:   Macros and macro variables within submit blocks are not resolved when you compile the SCL program. Instead, they are passed with the rest of the submit block to SAS software when the block is submitted. For more information about submit blocks, see Submitting SAS Statements and SQL Statements in SCL Programs.  [cautionend]

Note:   Using macros does not reduce the size of the compiled SCL code. Program statements that are generated by a macro are added to the compiled code as if those lines existed at that location in the program.  [cautionend]


Example

The following code defines two macros, VALAMNT and RATEAMNT, that validate values entered in two text entry controls, Amount and Rate.

%macro valamnt;
  if amount.text < 0 or amount.text > 500 then do;
    amount._erroron();
    _msg_='Amount must be between $0 and $500.';
    stop;
  end;
  else amount._erroroff();
%mend;
%macro rateamnt;
  if rate.text < 0 or rate.text > 1 then do;
    rate._erroron();
    _msg_='Rate must be between 0 and 1.';
    stop;
  end;
  else rate._erroroff();
%mend;

To use these two macros, create a frame that contains two Text Entry controls, Amount and Rate. Set the dataType attribute for each control to Numeric. Use the following code in the frame SCL:

INIT:
  control error;
  amount.text=0;
  rate.text=.5;
return;

MAIN:
  payment=amount*rate;
   put payment=;
return;

AMOUNT:
  %valamnt
return;

RATE:
  %rateamnt
return;

Previous Page | Next Page | Top of Page