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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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