DATA Step, Macro, Functions and more

macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

Accepted Solution Solved
Reply
Regular Contributor
Posts: 190
Accepted Solution

macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

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

 


Accepted Solutions
Solution
‎11-17-2015 01:34 AM
Super User
Posts: 5,500

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

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


All Replies
Trusted Advisor
Posts: 1,137

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

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
Regular Contributor
Posts: 190

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

Posted in reply to Jagadishkatam
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
Super User
Super User
Posts: 7,942

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

Solution
‎11-17-2015 01:34 AM
Super User
Posts: 5,500

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

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)

Regular Contributor
Posts: 190

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

Posted in reply to Astounding
thanks &explain the logic.
Super User
Posts: 5,500

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

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?

Regular Contributor
Posts: 190

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

Posted in reply to Astounding
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
Super User
Posts: 5,500

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

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

Regular Contributor
Posts: 190

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

Posted in reply to Astounding
and y are u using indirect reference as u haven't defined any 1 variable with different values..
Regular Contributor
Posts: 190

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

Posted in reply to Jagadishkatam
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 .
Super User
Super User
Posts: 7,942

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

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.

Regular Contributor
Posts: 190

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

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.
Super User
Posts: 11,343

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log


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.

Regular Contributor
Posts: 190

Re: macro to display%let a=10 b=12 c=15; %macro test(varlist=a b c test1); this values to the log

a=10
b=12
c=15
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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