SAS program to write the values of all local variables to the log

Reply
Regular Contributor
Posts: 190

SAS program to write the values of all local variables to the log

SAS program to write the values of all local variables to the log using do loop in a macro. 

 

Esteemed Advisor
Esteemed Advisor
Posts: 7,217

Re: SAS program to write the values of all local variables to the log

[ Edited ]

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;

Contributor
Posts: 45

Re: SAS program to write the values of all local variables to the log

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.

Regular Contributor
Posts: 190

Re: SAS program to write the values of all local variables to the log

%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.

Regular Contributor
Posts: 190

Re: SAS program to write the values of all local variables to the log

%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.

Regular Contributor
Posts: 190

Re: SAS program to write the values of all local variables to the log

%let a=10 b=12 c=15;
%macro test(varlist=a b c test1);
string=(varlist= a b c test1);
%do varlist=&a %to test1;

%put _local_ ;
%end;
%mend test;
options symbolgen mprint;
%test

will this work or retify it!
i want to display varlist= a b c test1 to the log with their values
Esteemed Advisor
Esteemed Advisor
Posts: 7,217

Re: SAS program to write the values of all local variables to the log

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.

Regular Contributor
Posts: 190

Re: SAS program to write the values of all local variables to the log

k thanks
Regular Contributor
Posts: 190

Re: SAS program to write the values of all local variables to the log

i want to reference this
%let a=10 b=12 c=15;
%macro test(varlist=a b c test1);
in my macro code and display this &a &b &c &test1 in the log with their respective values
Esteemed Advisor
Esteemed Advisor
Posts: 7,217

Re: SAS program to write the values of all local variables to the log

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. 

Regular Contributor
Posts: 190

Re: SAS program to write the values of all local variables to the log

i have to take the list & count each value separately and display individual value to the log. i do understand macros but am stuck at this program.
Respected Advisor
Posts: 3,836

Re: SAS program to write the values of all local variables to the log

[ Edited ]

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;

 

Ask a Question
Discussion stats
  • 11 replies
  • 497 views
  • 2 likes
  • 4 in conversation