Sample 46300: How to maintain macro variables across SAS sessions
SAS macro variables are stored in memory by default and are deleted when a SAS session ends. In order to use them in a new SAS session, you can save them from the SASHELP.VTABLE view.
The sample code on the Full Code tab illustrates how to save all of the global macro variables created within a SAS session and then recreate them in another SAS session.
Note: The values for SCOPE include AUTOMATIC, GLOBAL, and the name of any macro that contains any local macro variables. Automatic macro variables cannot be restated in subsequent SAS sessions. Local macro variables can be saved, but must be restated inside a macro definition in a subsequent SAS session.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample code saves all of the global macro variables from the SASHELP.VMACRO table, and places them into a permanent data set. CALL EXECUTE is used in a subsequent SAS session to restate the macro variables with %GLOBAL and %LET statements.
/* Place the GLOBAL macro variable(s) */
/* into a permanent SAS data set. */
libname test ".";
data test.vars;
set sashelp.vmacro(where=(scope='GLOBAL'));
run;
/* Submit the following in a subsequent SAS session: */
libname test ".";
/* Place the macro variable(s) back into the GLOBAL symbol table. */
data _null_;
set test.vars(where=(scope='GLOBAL'));
if substr(name,1,3) ne 'SYS' then do;
call execute('%global '||strip(name)||';');
call execute('%let '||strip(name)||'='||strip(value)||';');
end;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Date Modified: | 2012-05-07 10:50:22 |
Date Created: | 2012-04-13 11:01:38 |
Operating System and Release Information
SAS System | Base SAS | z/OS | 9.1 TS1M3 SP4 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.1 TS1M3 SP4 | |
Microsoft Windows XP 64-bit Edition | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Advanced Server | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Datacenter Server | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Server | 9.1 TS1M3 SP4 | |
Microsoft Windows 2000 Professional | 9.1 TS1M3 SP4 | |
Microsoft Windows NT Workstation | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.1 TS1M3 SP4 | |
Microsoft Windows Server 2003 Standard Edition | 9.1 TS1M3 SP4 | |
Microsoft Windows XP Professional | 9.1 TS1M3 SP4 | |
Windows Vista | 9.1 TS1M3 SP4 | |
Windows Vista for x64 | 9.1 TS1M3 SP4 | |
64-bit Enabled AIX | 9.1 TS1M3 SP4 | |
64-bit Enabled HP-UX | 9.1 TS1M3 SP4 | |
64-bit Enabled Solaris | 9.1 TS1M3 SP4 | |
HP-UX IPF | 9.1 TS1M3 SP4 | |
Linux | 9.1 TS1M3 SP4 | |
Linux on Itanium | 9.1 TS1M3 SP4 | |
OpenVMS Alpha | 9.1 TS1M3 SP4 | |
Solaris for x64 | 9.1 TS1M3 SP4 | |
Tru64 UNIX | 9.1 TS1M3 SP4 | |