%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
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
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 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.")
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;
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!
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.