BookmarkSubscribeRSS Feed
RTelang
Fluorite | Level 6

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

 

11 REPLIES 11
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

MaikH_Schutze
Quartz | Level 8

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.

RTelang
Fluorite | Level 6

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

RTelang
Fluorite | Level 6

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

RTelang
Fluorite | Level 6
%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
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

RTelang
Fluorite | Level 6
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
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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. 

RTelang
Fluorite | Level 6
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.
Patrick
Opal | Level 21

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;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 11 replies
  • 1419 views
  • 2 likes
  • 4 in conversation