- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Please let me know what am I missing here, Macro ABC and DEF are not resolving, call symputx is not creating these macro variables. I tried with & without masking functions.
Issue:
WARNING: Apparent symbolic reference ABC not resolved.
WARNING: Apparent symbolic reference DEF not resolved.
%macro get(name=); data _null_; set _x; ..... .... .... dsname = strip(upcase(scan(strip(reverse(ds)), 1, '.'))); call symputx("nrquote(&name.)", dsname );
run; %mend get; %get(name=ABC); %get(name=DEF);
%put ABC=&ABC;
%put DEF=&DEF;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
https://documentation.sas.com/doc/en/mcrolref/1.0/n0i4icf2nv7wu7n1lm4wf1epykfh.htm
use a %GLOBAL statement to give the variables global scope. By default, the scope is local.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
https://documentation.sas.com/doc/en/mcrolref/1.0/n0i4icf2nv7wu7n1lm4wf1epykfh.htm
use a %GLOBAL statement to give the variables global scope. By default, the scope is local.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Added %global and it worked, thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How do you know they weren't created? You didn't check them until after the macro ended. Once a macro stops running any local macro variables (symbols) are gone.
And why do you have the %NRQUOTE() function???
If you want the macro variables created in the GLOBAL symbol table you can ask CALL SYMPUTX() to do that for you.
call symputx("&name", dsname, 'g' );
But it might be more flexible if you had the macro make the macro variable global. That way you could do it only when the macro variable did not already exist in the calling environment.
%macro get(name=);
%if not %symexist(&name) %then %global &name;
....
call symputx("&name", dsname );
...
%mend get;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And why do you have the %NRQUOTE() function??? -----> I thought may be the macro variable resolution has something to do with the issue, so was trying out!
Below highlighted statement got me that this macro variable is available globally.
Didn't come across 'g' option puts macro variable in global symbol table. Glad to learn that, very helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Where did get that description?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That paper uses the word "can be accessed globally" in a less than precise way. Better: "can optionally be accessed globally." You are better off looking at SAS documentation, which is freely accessible on the web. As others have pointed out, using the 'G' parameter in SYMPUTX is an alternative to the %GLOBAL statement and is the easier solution. I suppose it depends on your programming style. If you want your macro to state up front what the global variables are, use %GLOBAL. If you want to specify it on the fly, particularly with macro variable names that are manufactured on the fly, use the 'G' parameter in SYMPUTX. When I was writing big macros, I liked to put %LOCAL and %GLOBAL statements up front listing all my macro variables, but that is certainly not required.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
call symputx("%nrquote(&name.)", dsname,'G');
CALL SYMPUTX(macro-variable,value<,symbol-table>);
Use the SYMPUTX third parameter to define the symbol-table for the variable being created. 'G' for global.