The macro exclusively queries the `sashelp.vmacro` system view, which contains metadata on all existing macro variables in the SAS session. No other external data sources are used or created.
1 Code Block
Macro Logic (WHERE clause construction)
Explanation : This first block initializes three local macro variables: `dsid` (for the dataset identifier), `rc` (for the return code), and `where` (for the filtering clause). It then constructs the `WHERE` clause that will be used to query the `sashelp.vmacro` view. If the `scope` parameter is provided, the search is limited to the specified scope, converted to uppercase. Otherwise, the search excludes the current macro's scope (`&sysmacroname`). Finally, the `WHERE` clause is completed to include the name of the macro variable to search for (`&mvar`), also converted to uppercase.
Explanation : This second block executes the verification logic. It uses the `%sysfunc(open())` function to open the `sashelp.vmacro` system view, applying the previously defined `WHERE` clause. If the dataset is successfully opened (i.e., `&dsid` is not null), the macro attempts to retrieve a record using `%sysfunc(fetch(&dsid))`. If a record is found (indicated by a return code other than -1), it means the macro variable exists in the searched scope. The dataset is then closed with `%sysfunc(close(&dsid))`. The macro returns `1` if the macro variable is found and `0` otherwise.
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.