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.
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?
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?
Thanks, Reeza. It does work now -- don't know why it didn't previously. Thanks a lot!
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.
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.
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.