BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
%let a=1;
%let b=New York;
%let c=12.5;

proc sql;
select scope,count(scope) label ='MACRO VARIABLE COUNT'
from dictionary.vmacro;
quit;

Here I want to count defined macro variables count  in work libraray

5 REPLIES 5
Tom
Super User Tom
Super User

The WORK library contains SAS datasets, catalogs etc.  Macro variables just live in memory.  You can see them using the DICTIONARY.MACROS table or SASHELP.VMACRO view to it.

 

If you want to count the number of macro variables then count the distinct names per scope.

proc sql;
 create table n_mvars as
  select scope,count(distinct name) as mvars
  from dictionary.macros
  group by scope
 ;
quit;

Results:

Obs    scope         mvars

 1     AUTOMATIC       72
 2     GLOBAL          71

novinosrin
Tourmaline | Level 20

Hi @BrahmanandaRao  I am not quite sure what's your question or the problem. I do understand you want to query dictionary tables that contain Macro related info. Since you are using Dictionary.XXXX tables, you should be directly querying the table MACRO instead of the VIEW aka VMACRO.

 

For example-

from dictionary.macros;

instead of

dictionary.vmacro;
BrahmanandaRao
Lapis Lazuli | Level 10
I defined three macro variables so how yo count only user defined macros variable in work library
PaigeMiller
Diamond | Level 26

@BrahmanandaRao wrote:
I defined three macro variables so how yo count only user defined macros variable in work library

The answer is ZERO. Macro variables are not in the WORK library. (Which was already explained by @Tom who said "The WORK library contains SAS datasets, catalogs etc. Macro variables just live in memory.")

--
Paige Miller
Ksharp
Super User

Use %put _user_; to get these user defined macro variables.

 

filename tmp temp;
proc printto log=tmp new;run;

%let a=1;
%let b=New York;
%let c=12.5;
%let d=12.5;


proc print data=sashelp.class;run;
%put start;
%put _user_;
%put end;
proc printto;run;



data _null_;
infile tmp  end=last;
input;
retain start;
if _infile_=: 'start' then start=1;
if start then n_macro_var+1;
if _infile_=: 'end' then do;
n_macro_var=n_macro_var-4;
putlog 'number of user defined macro variable is'  n_macro_var best8.;
stop;
end;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 1253 views
  • 0 likes
  • 5 in conversation