BookmarkSubscribeRSS Feed
rpg163
Calcite | Level 5

Hi,

     I try to use array in Maro, but problem occurs with dim, here it is,

    

     %macro a;

     data a;

          set b;

          array a(*) _numeric_;

          array b(*);

          %do i= 1 %to dim(a);

               b(i)=a(i);

          %end;

      run;

     %mend;

SAS shows it can not find the operator in expression: dim(a).

Can someone please help. Thanks!

2 REPLIES 2
Tom
Super User Tom
Super User

The macro language is processes before the generated code is run by SAS.  So you cannot reference the value of a data step variable or function like DIM().  But you do not need macro language for what you are doing. Just use a normal data step DO loop instead. 

The only need for macro logic in your program would be to set the dimensions of the B array.  You could possibly just set an upper bound and create more variables than you need.

Are you planning to create NEW variables with that array?  Are you sure that none of the variables in dataset A look like B1, B2, etc that your ARRAY statement will generate?  If they do then you will be referencing the same variable in both the A and the B array.

%let maxdim=100;

data a;

  set b;

  array a _numeric_;

  array b(&maxdim);

  if dim(a) > &maxdim then abort;

  do i= 1 to dim(a);

    b(i)=a(i);

  end;

run;

rpg163
Calcite | Level 5

THX,

I just find this is the same question with follow thread:

http://communities.sas.com/message/108353#108353,

which you have already responded.

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!

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