global macro variable using call symput in macro defintion

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

global macro variable using call symput in macro defintion

% macro test;

  data _null_;

    call symputx('name', 'Philip')

run;

%mend test;

%test

%put _global_;

I thought call symputx creates local macro variable in the macro definition.  After checking name is global macro variable.  I appreciate clarification in this.

Thank you.


Accepted Solutions
Solution
‎07-06-2014 07:36 PM
SAS Super FREQ
Posts: 8,868

Re: global macro variable using call symput in macro defintion

Posted in reply to kaushal2040

Hi:

  There is a search path that is used to determine whether you create your macro variable in a GLOBAL or LOCAL table. You need to read about it in the documentation. When inside a macro that does not otherwise need/create a local table, your macro variable will be written to the global table. The beauty of CALL SYMPUTX is that you can CONTROL where the macro variable will be written. See the attached screen shot. The 3rd argument to the call routine allows you to specify a string that is the location: "L" for local or "G" for global or Your macro definition does not use or create a LOCAL symbol table. 'F' means write it in the most local table IF the macro variable is found. Look at the attached screen shot for an example of using 'L' and 'G' -- that's where I would recommend starting.

cynthia


force_write_local_or_global.png

View solution in original post


All Replies
Solution
‎07-06-2014 07:36 PM
SAS Super FREQ
Posts: 8,868

Re: global macro variable using call symput in macro defintion

Posted in reply to kaushal2040

Hi:

  There is a search path that is used to determine whether you create your macro variable in a GLOBAL or LOCAL table. You need to read about it in the documentation. When inside a macro that does not otherwise need/create a local table, your macro variable will be written to the global table. The beauty of CALL SYMPUTX is that you can CONTROL where the macro variable will be written. See the attached screen shot. The 3rd argument to the call routine allows you to specify a string that is the location: "L" for local or "G" for global or Your macro definition does not use or create a LOCAL symbol table. 'F' means write it in the most local table IF the macro variable is found. Look at the attached screen shot for an example of using 'L' and 'G' -- that's where I would recommend starting.

cynthia


force_write_local_or_global.png
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 288 views
  • 0 likes
  • 2 in conversation