Thanks to Kit Baum, a new command, preserve_globals, is now available from the SSC.
The command does what its name implies: it preserves global macros, i.e., protects global macros from being overwritten. Earlier versions of preserve_globals appeared in a discussion started by Clyde Schechter. To quote his problem statement:
preserve_globals is a suggested solution to this problem.
Here is a silly example that first illustrates the problem, then demonstrates the solution. Suppose, there is a program:
that we want to call from within a do-file. Suppose the do-file reads:
The output is
Here is how we solve the problem:
The output:
The command does what its name implies: it preserves global macros, i.e., protects global macros from being overwritten. Earlier versions of preserve_globals appeared in a discussion started by Clyde Schechter. To quote his problem statement:
Originally posted by Clyde Schechter
View Post
Here is a silly example that first illustrates the problem, then demonstrates the solution. Suppose, there is a program:
Code:
program global_data_star_trek global data "a character from Star Trek: The Next Generation" display "Data is ${data}" end
Code:
// store the path to the dataset in a global macro global data "C:\mydata" // call a command global_data_star_trek // reference the global macro; expect to see the path to the dataset display "data is ${data}"
Code:
. // define a global macro for the path to the dataset . global data "C:\mydata" . . // call a command . global_data_star_trek Data is a character from Star Trek: The Next Generation . . // reference the global macro . display "data is ${data}" data is a character from Star Trek: The Next Generation
Code:
// define a global macro for the path to the dataset global data "C:\mydata" // call a command; but presreve global macros preserve_globals global_data_star_trek // <- modified line // reference the global macro display "data is ${data}"
Code:
. // define a global macro for the path to the dataset . global data "C:\mydata" . . // call a command; presreve global macros . preserve_globals global_data_star_trek // <- modified line Data is a character from Star Trek: The Next Generation . . // reference the global macro . display "data is ${data}" data is C:\mydata
Comment