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

I have a question on the use of %macro. I am using the code of a published paper to build my own indicator  and I faced many  problems. 

 

Code :   

 

%macro decomp(ctr,num);
proc iml;
use vbs;
read all var _all_ into vbs;
use texpfd(drop = ctr sec domdmd texpfd) ;
read all var _all_ into expf;
/*make DVAsh to zero */
k = 0;
do i = 1 to 1435 by 35;
  j = i+34;
  k = k + 1;
rows = i:j;
cols = k:k;
vbs[rows,cols] = 0;
end;
indvaexp=vbs[,&num]#expf;
quit;
%mend decomp
 
my problem is  %macro (ctr ,num)  . Is num refering to the fact that it is a numeric variable ? 
and the last code indvaexp=vbs[,&num]#expf. What is the meaning of vbs[,&num] . I know that we use & to make reference to a macro variable but I tried to compute without macro ( indvaexp=vbs#expf) but I don't get the same result . 
 
Can you help me please ?
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

 

%macro decomp(ctr,num);

Here, num is just defined as the second positional parameter of the macro. You can reference it just like any locally defined macro variable throughout the macro.

indvaexp=vbs[,&num]#expf;

Here &num is referenced. When the macro resolves and is executed by the macro preprocessor, &num is replaced by whatever was supplied as a parameter when the macro was called.

eg

%decomp(x,y)

will resolve this particular line to

indvaexp=vbs[,y]#expf;

 Think of the macro preprocessor as a quite versatile text replacement tool.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

 

%macro decomp(ctr,num);

Here, num is just defined as the second positional parameter of the macro. You can reference it just like any locally defined macro variable throughout the macro.

indvaexp=vbs[,&num]#expf;

Here &num is referenced. When the macro resolves and is executed by the macro preprocessor, &num is replaced by whatever was supplied as a parameter when the macro was called.

eg

%decomp(x,y)

will resolve this particular line to

indvaexp=vbs[,y]#expf;

 Think of the macro preprocessor as a quite versatile text replacement tool.

IBNANA
Calcite | Level 5

Thank you  for your  answer 

ballardw
Super User

@IBNANA wrote:

I have a question on the use of %macro. I am using the code of a published paper to build my own indicator  and I faced many  problems. 

 

Code :   

 

%macro decomp(ctr,num);
proc iml;
use vbs;
read all var _all_ into vbs;
use texpfd(drop = ctr sec domdmd texpfd) ;
read all var _all_ into expf;
/*make DVAsh to zero */
k = 0;
do i = 1 to 1435 by 35;
  j = i+34;
  k = k + 1;
rows = i:j;
cols = k:k;
vbs[rows,cols] = 0;
end;
indvaexp=vbs[,&num]#expf;
quit;
%mend decomp
 
my problem is  %macro (ctr ,num)  . Is num refering to the fact that it is a numeric variable ? 
and the last code indvaexp=vbs[,&num]#expf. What is the meaning of vbs[,&num] . I know that we use & to make reference to a macro variable but I tried to compute without macro ( indvaexp=vbs#expf) but I don't get the same result . 
 
Can you help me please ?

If the paper you reference that gave you the base code did not document the usage of any of the macro parameters I would hesitate to rely on the paper or the code too much.

Especially if there are no validations of the parameters in regards to the data or code use. Any program should document the expected inputs somewhere such as a comment block. It should have some explanation of what the whole macro does and details of the macro parameters and if there isn't any validation of the parameter values then the validation you have to perform before using the macro.

 

Something of concern: there macro parameter CTR is apparently not even used. I would expect to see at least one reference to &ctr in the code.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 777 views
  • 2 likes
  • 3 in conversation