BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RTelang
Fluorite | Level 6

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

 want to display varlist to the log with the variables & their values.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Are you willing to accept a solution that works, even if you probably can't understand it?

 

%macro test (varlist=);

%local i nextword;

%do i=1 %to %sysfunc(countw(&varlist));

   %let nextword = %scan(&varlist, &i);

   %put &nextword = &&&nextword;

%end;

%mend test;

%test (varlist=a b c)

View solution in original post

14 REPLIES 14
Jagadishkatam
Amethyst | Level 16
Try

%let a=10;
%let b=12;
%let c=15;

%put &a &b &c

This will display the values of macro variables a b and c to the log
Thanks,
Jag
RTelang
Fluorite | Level 6
no no
%let a=10 b=12 c=15;
%macro test (varlist= a b c)
i want to display varlist variables reference & a &b &c
Astounding
PROC Star

Are you willing to accept a solution that works, even if you probably can't understand it?

 

%macro test (varlist=);

%local i nextword;

%do i=1 %to %sysfunc(countw(&varlist));

   %let nextword = %scan(&varlist, &i);

   %put &nextword = &&&nextword;

%end;

%mend test;

%test (varlist=a b c)

Astounding
PROC Star

Based on this original statement:

 

%let a=10 b=12 c=15;

 

There would be too much to explain.  You would really need to read a book on macro language to come up to speed on the basics.  If you are willing to do the work, here is a list of topics you would need to research:

 

What is the purpose of a %local statement?

 

What is the purpose of %sysfunc?

 

What does the COUNTW function do?

 

What does the %SCAN function do?

 

How do you resolve &&&nextword?

RTelang
Fluorite | Level 6
thanks i know macro i am trying to ask u purpose of ur logic does it display & read every single variable a b c with their respective value
Astounding
PROC Star

OK, assuming you are comfortable with the topics that I listed, here is the general idea of the logic.

 

Each iteration through the %DO loop picks off the name of the next macro variable in &VARLIST.  It gets stored in &NEXTNAME.  The %PUT statement then writes the name of the macro variable (&NEXTNAME) and its value (&&&NEXTNAME).

RTelang
Fluorite | Level 6
and y are u using indirect reference as u haven't defined any 1 variable with different values..
RTelang
Fluorite | Level 6
what i mean to ask from my question is in a random macro data session i want to display variables and their values in d log i need a generic code to do it. so i gave a example
%let a=10 b=12 c=15;
%macro test(varlist= a b c );
i want to display a b c from varlist with its defined values can i use scan or substrng function to read d chars & then display it in d log.
i cant find a logic to do so, thus am asking u for a solution or a code .
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, I am not sure another way of putting this.  Your code:

%let a=10 b=12 c=15;

 

Creates a macro variable called A, with the character string "10 b=12 c=15".  it doesn't create three macro variables as you seem to think it does. 

To display macro variables you can use

%put _local_;  

%put _global_;

 

Or query the SASHELP.VMACRO dataset.

RTelang
Fluorite | Level 6
yes ur argument is correct its a single macro varlist=a b c so i want to read 1 char at a time using scan or substring & display it.or with data null also u can do it.
ballardw
Super User

@RTelang wrote:
yes ur argument is correct its a single macro varlist=a b c so i want to read 1 char at a time using scan or substring & display it.or with data null also u can do it.

Time to show what you are expecting to see in the log for your example input. Exactly, not a description.

Something like this?

 

1

0

 

b

=

1

2

 

or

 

1

0

 

b

=

12

that is a very different solution.

or

 

a

b

c

t

e

s

t

1

 

I really can't tell at all from your descriptions what you think you want.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 14 replies
  • 2112 views
  • 0 likes
  • 5 in conversation