SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Rain_28
Fluorite | Level 6

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;

 
1 ACCEPTED SOLUTION

Accepted Solutions
WarrenKuhfeld
Ammonite | Level 13

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.

View solution in original post

9 REPLIES 9
WarrenKuhfeld
Ammonite | Level 13

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.

Rain_28
Fluorite | Level 6
Isn't Call Symputx creates a global macro variable? Available through out the program? That's what I understood reading the papers.

Added %global and it worked, thanks!
Tom
Super User Tom
Super User

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;

 

Rain_28
Fluorite | Level 6

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. 

Rain_28_0-1740088717872.png

 

Didn't come across 'g' option puts macro variable in global symbol table. Glad to learn that, very helpful.

Tom
Super User Tom
Super User

Where did get that description?

WarrenKuhfeld
Ammonite | Level 13

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.

data_null__
Jade | Level 19
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.  

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1004 views
  • 5 likes
  • 4 in conversation