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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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