BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lizzy28
Quartz | Level 8

I have windows 7 and SAS 9.3.

I am learning macro, and this is my first time to do array within a macro program. I know that there is a function for it, but cannot really understand the function. There are 15 variables (proc1-proc15) with the same attributes in 10 datasets (data1-data10). Here is my program:

%macro create_var();

   %do i=1 to 10;

   data mylib.data&i; set mylib.data&i;

    tx=0;

   array proc[15] proc1-proc15;

       do j=1 to 15;

       if proc(j) in (8540, 8541, 8542) then tx=1;

       end;

   run;

%end;

%mend;

%create_var();

run;

The red part is my array in regular data step. Anyone can teach me how to modify it to make the macro program work? Thanks a lot.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

There actually isn't something called a macro array. There are some workarounds but that's what they are.

Your code appears correct, what part do you need to change to make it macro?

View solution in original post

3 REPLIES 3
Reeza
Super User

There actually isn't something called a macro array. There are some workarounds but that's what they are.

Your code appears correct, what part do you need to change to make it macro?

lizzy28
Quartz | Level 8

Thanks, Reeza. It does work now -- don't know why it didn't previously. Thanks a lot!

ballardw
Super User

A minor bit for efficiency. It looks like you don't care which variable contributes the values in the list so as soon as the first one is true you could leave the loop;

   array proc[15] proc1-proc15;

       do j=1 to 15;

       if proc(j) in (8540, 8541, 8542) then tx=1;

       if tx=1 then leave;

       end;

if proc1 is 8540 then this avoids comparing proc2-15. Which may save some time in large datasets.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1350 views
  • 4 likes
  • 3 in conversation