04-14-2017 03:12 AM
so below is the structure of my program (pesudo code)
%macro someMacro (list)
%do list=1 to list=<lastIndex>
when list = 1
access 1,2,5 in loop
when list = 2
access 2,4,6 in loop
how do I impliment a sas macro with passing a list or array as a parameter to the macro?
My problem is similar to this topic.
Only difference is that I need to pass more than 1 variable in one iteration.
04-14-2017 06:45 AM
It would be less messy if you could change the format of the incoming list. Are you able to get the equivalent of:
%let list = 1 2 5 # 2 4 6;
The choice of delimiter isn't important, but removing the brackets and commas is helpful.
04-14-2017 08:46 AM
Don't use comma as the delimiter. In that sense the advice from SAS in that posting should be first to use spaces or some other character besides comma as your delmiter. This will eliminate the need for a lot of macro quoting that makes the code hard to read and also end up confusing the SAS parser.
To generate your type of multi-dimensional list just need to use more than one type of delimiter. Typically I would use space first and add | as the next delimiter.
%macro someMacro (list); %local i sentence j word; %do i = 1 %to %sysfunc(countw(&list,|)); %let sentence = %scan(&list,&i,|); %do j = 1 %to %sysfunc(countw(&sentence)); %let word = %scan(&sentence,&j); %put (&i,&j) = &word; %end; %end; %mend someMacro; %someMacro(1 2 3|4 5 6);