%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.
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)
This is a duplicate post:
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)
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?
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).
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 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.
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!
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.
Ready to level-up your skills? Choose your own adventure.