Chapter Contents |
Previous |
Next |
SAS Component Language: Reference |
Examples of types of information that you frequently need to pass between entries in an application include
Storing and Retrieving Macro Variable Values |
To assign a literal value to a macro variable in an SCL program,
you can use the standard macro variable assignment statement, %LET. For example,
the following statement assigns the literal value
sales
(not the value of
an SCL variable named SALES) to a macro variable named DSNAME:
%let dsname=sales;
Macro variable assignments are evaluated when SCL programs are compiled, not when they are executed. Thus, the %LET statement is useful for assigning literal values at compile time. For example, you can use macro variables defined in this manner to store a value or block of text that is used repeatedly in a program. However, you must use a different approach if you want to store the value of an SCL variable in a macro variable while the SCL program executes (for example, to pass values between SCL programs).
Macro variables store only strings of text characters, so numeric values are stored as strings of text digits that represent numeric values. To store values so that they can be retrieved correctly, you must use the appropriate CALL routine. The following routines store the value of a macro when an SCL program runs:
call symput('table',sales);
To retrieve the value of a macro variable in an SCL program, you can use a standard macro variable reference. In the following example, the value of the macro variable TABLE is substituted for the macro variable reference when the program is compiled:
dsn="&table";
The function that you use to retrieve the value of a macro variable determines how the macro variable value is interpreted. The following functions return the value of a macro variable when a program runs:
Using the Same Name for Macro Variables and SCL Variables |
dsname='sasuser.class'; call symput('dsname','sasuser.houses'); submit continue; proc print data=&dsname; run; proc print data=&&dsname; run; endsubmit;
The program produces the following:
proc print data=sasuser.class; run; proc print data=sasuser.houses; run;
Using Automatic Macro Variables |
When you use automatic macro variables, remember to use the appropriate routines and functions to set and retrieve variable values. For example, consider the following program statements. The first uses a macro variable reference:
jobid="&sysjobid";The second uses an SCL function:
jobid=symget('sysjobid');
The macro variable reference, designated by the & (ampersand), is evaluated when the program is compiled. Thus, the identifier value for the job or process that compiles the program is assigned to the variable JOBID. Assuming that the preceding two statements were compiled by an earlier SAS process, if you want the JOBID variable to contain the identifier for the current process, then you must use the second form (without the &). The SYMGET function extracts the macro variable value from the global symbol table at execution.
Note: The values that are returned by SYSJOBID and other
automatic macro variables depend on your host operating system.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.