SAS program to write the values of all local variables to the log using do loop in a macro.
It doesn't make much sense to have a do - loop, just do:
%put _local_;
To test:
%macro tmp;
%local temp;
%let temp=abc;
%put _local_;
%mend tmp;
%tmp;
Completely agree. Can't see what a DO loop may accomplish. The %put _local_ line of SAS code will give you the information you asked for in the log file.
Maybe you can tell us a little more about why you had considered/asked to have this done using a DO loop.
%let a=10 b=12 c=15;
%macro test(varlist=a b c test1);
hi Schutze this is the example am talking about,
a b c values are defined so using varlist parameter i have to access these values & display the in the log with their respective variables.
%let a=10 b=12 c=15;
%macro test(varlist=a b c test1);
hello RW9 this is the example am talking about,
a b c values are defined so using varlist parameter i have to access these values & display
the in the log with their respective variables. thanks.
Hi,
Ok, lets start this again. Start from the beginning, not half way through. What is it your trying to do. I do not see any reason why you would be passing a list of macro variables into a macro via a macro variable. This seems totally illogical. In theory you could use the metadata table to print to log:
%let a=10 b=12 c=15;
%macro test(varlist=a b c test1);
proc print data=sashelp.vmacro;
run;
%mend test;
%test;
However, if you run this you will see that &A is the only macro variable created in the first statement, and it represents the text: "10 b=12 c=15". What I would suggest is that you go back and have a look at what macros/variables are, and how they work, as what you are doing doesn't make sense.
Hi,
Please read my post thoroughly, and run the code given. You don't seem to understand how macros work. This code:
%let a=10 b=12 c=15;
Creates a macro variable called a which contains the string "10 b=12 c=15".
Secondly, what is it your trying to do, why do you have a macro parameter with a list of what I assume from the text is variables, and yet seem to want to use them as macro variables? Please state what you are doing, post datastep test data and required output, as the code provided makes no sense.
Are you talking about macro variables? If so then it's very easy.
You don't need below in a macro do loop as these reserved keywords will access all macro variables in scope.
%put _local_;
%put _global_;
%put _automatic_;
%put _all_;
Alternatively you can also query the macro dictionary table.
proc sql;
select * from dictionary.macros
;
quit;
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.