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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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