Problem Note 51984: A %LET statement might generate unexpected results when used to create a macro variable name in open code
Unexpected results might occur when using an expression to build a macro variable in a %LET statement in open code. In the example code below, we are trying to create a macro variable called BB_AA with a value of 100:
%macro abc(value);
%let i=%length(&value);
%substr(&value,1,&i)
%mend;
%let a=bb;
%let %abc(&a)_aa=100;
%put _user_;
The code incorrectly generates a macro variable called BB with a value of _aa=100.
To circumvent the problem, do one of the following:
- Use the %UNQUOTE macro function. For example:
%macro abc(value);
%let i=%length(&value);
%substr(&value,1,&i)
%mend;
%let a=bb;
%let %unquote(%abc(&a)_aa)=100;
%put _user_;
- Place the %LET statements within a macro definition. For example:
%macro abc(value);
%let i=%length(&value);
%substr(&value,1,&i)
%mend;
%macro test;
%let a=bb;
%let %abc(&a)_aa=100;
%put _user_;
%mend test;
%test
- Remove the macro call from the expression. For example:
%macro abc(value);
%let i=%length(&value);
%substr(&value,1,&i)
%mend;
%let a=bb;
%let temp=%abc(&a);
%let &temp._aa=100;
%put _user_;
Operating System and Release Information
SAS System | Base SAS | z/OS | 9.3 TS1M0 | 9.4 TS1M2 |
Z64 | 9.3 TS1M0 | 9.4 TS1M2 |
Microsoft® Windows® for x64 | 9.3 TS1M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.3 TS1M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.3 TS1M0 | |
Microsoft Windows Server 2003 Standard Edition | 9.3 TS1M0 | |
Microsoft Windows Server 2003 for x64 | 9.3 TS1M0 | |
Microsoft Windows Server 2008 | 9.3 TS1M0 | |
Microsoft Windows Server 2008 R2 | 9.3 TS1M0 | |
Microsoft Windows Server 2008 for x64 | 9.3 TS1M0 | |
Microsoft Windows XP Professional | 9.3 TS1M0 | |
Windows 7 Enterprise 32 bit | 9.3 TS1M0 | 9.4 TS1M2 |
Windows 7 Enterprise x64 | 9.3 TS1M0 | 9.4 TS1M2 |
Windows 7 Home Premium 32 bit | 9.3 TS1M0 | 9.4 TS1M2 |
Windows 7 Home Premium x64 | 9.3 TS1M0 | 9.4 TS1M2 |
Windows 7 Professional 32 bit | 9.3 TS1M0 | 9.4 TS1M2 |
Windows 7 Professional x64 | 9.3 TS1M0 | 9.4 TS1M2 |
Windows 7 Ultimate 32 bit | 9.3 TS1M0 | 9.4 TS1M2 |
Windows 7 Ultimate x64 | 9.3 TS1M0 | 9.4 TS1M2 |
Windows Vista | 9.3 TS1M0 | |
Windows Vista for x64 | 9.3 TS1M0 | |
64-bit Enabled AIX | 9.3 TS1M0 | 9.4 TS1M2 |
64-bit Enabled HP-UX | 9.3 TS1M0 | 9.4 TS1M2 |
64-bit Enabled Solaris | 9.3 TS1M0 | 9.4 TS1M2 |
HP-UX IPF | 9.3 TS1M0 | 9.4 TS1M2 |
Linux | 9.3 TS1M0 | 9.4 TS1M2 |
Linux for x64 | 9.3 TS1M0 | 9.4 TS1M2 |
Solaris for x64 | 9.3 TS1M0 | 9.4 TS1M2 |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
Using an expression to build a macro variable name in a %LET statement, where the name consists of more than one token, can generate unexpected results.
Type: | Problem Note |
Priority: | low |
Date Modified: | 2014-01-10 10:15:52 |
Date Created: | 2014-01-07 14:12:13 |