40
41 %level1;
WARNING: Argument 1 to %SYSMEXECNAME function is out of range.
%sysmexecname(5)=
%sysmexecname(4)=LEVEL4
%sysmexecname(3)=LEVEL3
%sysmexecname(2)=LEVEL2
%sysmexecname(1)=LEVEL1
%sysmexecname(0)=OPEN CODE
WARNING: Argument 1 to %SYSMEXECNAME function is out of range.
%sysmexecname(-1)=
42
Macro A calls macro B. Macro C calls macro B. A call to %SYSMEXECDEPTH
placed in macro C would return the value 2 for macro B.
If the macro C wanted to know the name of the macro that had called it, it could call
%SYSMEXECNAME with %SYSMEXECNAME(%SYSMEXECDEPTH-1 (the value of
the
n argument being %SYSMEXECDEPTH, its own nesting level, minus one). That
call to %SYSMEXECNAME would return the value B.
%SYSMEXECNAME Function
Returns the name of the macro executing at a requested nesting level.
Type: Macro Function
Tip: %SYSMEXECNAME and %SYSMEXECDEPTH were implemented to be used
together, but it is not required.
See: %SYSMEXECDEPTH function
Syntax
%SYSMEXECNAME(n)
Required Argument
n
The nesting level at which you are requesting the macro name.
0 open code
>0 nesting level
Details
The %SYSMEXECNAME function returns the name of the macro executing at the n
nesting level. The following three scenarios are shown in the example below.
If n = 0, open code is returned.
If n >%SYSMEXECDEPTH, a null string is returned and a WARNING diagnostic
message is issued to the SAS log.
If n<0, a null string is returned and a WARNING diagnostic message is issued to the
SAS log.
290 Chapter 17 Macro Functions
3 %put %sysmexecdepth; /* The macro execution depth of
Open Code is zero */
0
4 %put %sysmexecname(%sysmexecdepth);
OPEN CODE
5 %put %sysmexecname(%sysmexecdepth + 1);
WARNING: Argument 1 to %SYSMEXECNAME function is out of range.
6 %put %sysmexecname(%sysmexecdepth - 1);
WARNING: Argument 1 to %SYSMEXECNAME function is out of range.
%SYSPROD Function
Reports whether a SAS software product is licensed at the site.
Type: Macro function
See: “%SYSEXEC Statement” on page 338, “SYSSCP and SYSSCPL Automatic Macro
Variables” on page 224, and “SYSVER Automatic Macro Variable” on page 232
Syntax
%SYSPROD(product)
Required Argument
product
can be a character string or text expression that yields a code for a SAS product. The
following are commonly used codes:
Table 17.3 Commonly Used Codes
AF CPE GRAPH PH-CLINICAL
ASSIST EIS IML QC
BASE ETS INSIGHT SHARE
CALC FSP LAB STAT
CONNECT GIS OR TOOLKIT
For codes for other SAS software products, see your on-site SAS support personnel.
Details
%SYSPROD can return the following values:
%SYSPROD Function 291
Table 17.4 %SYSPROD Values and Descriptions
Value Description
1 The SAS product is licensed.
0 The SAS product is not licensed.
−1 The product is not Institute software (for example, if the product code is
misspelled).
Example: Verifying SAS/GRAPH Installation Before
Running the GPLOT Procedure
This example uses %SYSPROD to determine whether to execute a PROC GPLOT
statement or a PROC PLOT statement, based on whether SAS/GRAPH software has
been installed.
%macro runplot(ds);
%if %sysprod(graph)=1 %then
%do;
title "GPLOT of %upcase(&ds)";
proc gplot data=&ds;
plot style*price / haxis=0 to 150000 by 50000;
run;
quit;
%end;
%else
%do;
title "PLOT of %upcase(&ds)";
proc plot data=&ds;
plot style*price;
run;
quit;
%end;
%mend runplot;
%runplot(Sasuser.Houses)
When this program executes and SAS/GRAPH is installed, the following statements are
generated:
TITLE "GPLOT of SASUSER.HOUSES";
PROC GPLOT DATA=SASUSER.HOUSES;
PLOT STYLE*PRICE / HAXIS=0 TO 150000 BY 50000;
RUN;
%UNQUOTE Function
During macro execution, unmasks all special characters and mnemonic operators for a value.
Type: Macro function
See: “%BQUOTE and %NRBQUOTE Functions” on page 260, “%NRBQUOTE Function”
on page 264, “%NRQUOTE Function” on page 264, “%NRSTR Function” on page
292 Chapter 17 Macro Functions
265, “%QUOTE and %NRQUOTE Functions” on page 266, “%STR and %NRSTR
Functions” on page 272, and “%SUPERQ Function” on page 277
Syntax
%UNQUOTE(character-string | text-expression)
Details
The %UNQUOTE function unmasks a value so that special characters that it might
contain are interpreted as macro language elements instead of as text. The most
important effect of %UNQUOTE is to restore normal tokenization of a value whose
tokenization was altered by a previous macro quoting function. %UNQUOTE takes
effect during macro execution.
For more information, see “Macro Quoting” on page 82.
Example: Using %UNQUOTE to Unmask Values
This example demonstrates a problem that can arise when the value of a macro variable
is assigned using a macro quoting function and then the variable is referenced in a later
DATA step. If the value is not unmasked before it reaches the SAS compiler, the DATA
step does not compile correctly and it produces error messages. Although several macro
functions automatically unmask values, a variable might not be processed by one of
those functions.
The following program generates error messages in the SAS log because the value of
TESTVAL is still masked when it reaches the SAS compiler.
%let val = aaa;
%let testval = %str(%'&val%');
data _null_;
val = &testval;
put 'VAL =' val;
run;
This version of the program runs correctly because %UNQUOTE unmasks the value of
TESTVAL.
%let val = aaa;
%let testval = %str(%'&val%');
data _null_;
val = %unquote(&testval);
put 'VAL =' val;
run;
This program prints the following to the SAS log:
VAL=aaa
%UPCASE and %QUPCASE Functions
Convert values to uppercase.
Type: Macro function
%UPCASE and %QUPCASE Functions 293
See: “%LOWCASE and %QLOWCASE Autocall Macros” on page 184, “%NRBQUOTE
Function” on page 264, and “%QLOWCASE Autocall Macro” on page 186
Syntax
%UPCASE(character-string | text-expression)
%QUPCASE(character-string | text-expression)
Details
The %UPCASE and %QUPCASE functions convert lowercase characters in the
argument to uppercase. %UPCASE does not mask special characters or mnemonic
operators in its result, even when the argument was previously masked by a macro
quoting function.
If the argument contains a special character or mnemonic operator, listed below, use
%QUPCASE. %QUPCASE masks the following special characters and mnemonic
operators in its result:
& % ' " ( ) + − * / < > = ¬ ^ ~ ; , # blank
AND OR NOT EQ NE LE LT GE GT IN
%UPCASE and %QUPCASE are useful in the comparison of values because the macro
facility does not automatically convert lowercase characters to uppercase before
comparing values.
Comparisons
%QUPCASE masks the same characters as the %NRBQUOTE function.
To convert characters to lowercase, use the %LOWCASE or %QLOWCASE
autocall macro.
Examples
Example 1: Capitalizing a Value to Be Compared
In this example, the macro RUNREPT compares a value input for the macro variable
MONTH to the string DEC. If the uppercase value of the response is DEC, then PROC
FSVIEW runs on the data set Reports.EndYear. Otherwise, PROC FSVIEW runs on the
data set with the name of the month in the Reports data library.
%macro runrept(month);
%if %upcase(&month)=DEC %then
%str(proc fsview data=reports.endyear; run;);
%else %str(proc fsview data=reports.&month; run;);
%mend runrept;
You can invoke the macro in any of these ways to satisfy the %IF condition:
%runrept(DEC)
%runrept(Dec)
%runrept(dec)
Example 2: Comparing %UPCASE and %QUPCASE
These statements show the results produced by %UPCASE and %QUPCASE:
%let a=begin;
294 Chapter 17 Macro Functions
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset