2 dimensional macro array in loop (%do)

Reply
Contributor
Posts: 35

2 dimensional macro array in loop (%do)

Hello,

 

I need to declare a  2D macro array before the following code and fill the partucular elements of the array with some value. 

 


%do ii=1 %to &countlnt;
%let row = %eval(%scan(&myw,&ii , *));   --> this will be the row of the macro array
%let col = %eval(%scan(&myy,&ii , *)-&currentYear+11);  --> this will be the column of the macro array
%let value = %eval(%scan(&mycount,&ii , *));  --> and this is the value for the cell (row,col)
%put &mycol ;
%end;

 

I am very new in SAS. I would really be appriciated if somebody help me. Thank you in advance!

 

Super User
Posts: 5,085

Re: 2 dimensional macro array in loop (%do)

This is likely the wrong assignment for someone who is relatively new to SAS.  DATA steps permit 2D arrays.  Macros really don't support arrays at all.  So check with a local SAS programmer to see that this is the right approach for the problem you are trying to solve.  At any rate, you can simulate an array in macro language by using naming conventions for your macro variables.  For example, you could add this statement:

 

%let val_&row._&col. = &value;

 

That might replace the %PUT statement (which would likely have to be changed anyway, since there is nothing in this code that creates &MYCOL).

 

At the end of this, at least for testing purposes, you might want to see what you have created, by adding:

 

%put _user_;

Ask a Question
Discussion stats
  • 1 reply
  • 274 views
  • 0 likes
  • 2 in conversation