Help using Base SAS procedures

how can I use an array dimension in a macro?

Reply
New Contributor
Posts: 4

how can I use an array dimension in a macro?

%macro aaaa();
data a;
array new{4} score1-score4;
%do i=1 %to dim(new) %by 1;
new{i}=10;
%end;

proc print data=a;
run;
%mend aaaa;
%aaaa();

log window:
MPRINT(AAAA): array new{4} score1-score4;
ERROR: Required operator not found in expression: dim(new)
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro AAAA will stop executing.
Super Contributor
Super Contributor
Posts: 3,174

Re: how can I use an array dimension in a macro?

Suggest you use a macro variable declared with a %LET statement to identify the maximum array element/variable.

Scott Barry
SBBWorks, Inc.

Recommended Google advanced search argument this topic/post:

using macro variables site:sas.com
Regular Contributor
Posts: 165

Re: how can I use an array dimension in a macro?

I could be wrong but I think you want to use the regular data step do loop instead of %do. %Do is something you should use if you want to iterate blocks of code such as series of data steps or procs. I dont think %do can access the array in the data step.
New Contributor
Posts: 4

Re: how can I use an array dimension in a macro?

You are right. Thanks!
Ask a Question
Discussion stats
  • 3 replies
  • 239 views
  • 0 likes
  • 3 in conversation