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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 754 views
  • 0 likes
  • 5 in conversation