BookmarkSubscribeRSS Feed
samira
Obsidian | Level 7

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!

 

1 REPLY 1
Astounding
PROC Star

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_;

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
  • 1 reply
  • 1050 views
  • 0 likes
  • 2 in conversation