BookmarkSubscribeRSS Feed
captainprice0
Fluorite | Level 6

Hi,

 

so below is the structure of my program (pesudo code)

 

list = 

[1,2,5],

[2,4,6];

 

%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

 

%mend someMacro()

 

someMacro(list)


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.

http://support.sas.com/kb/26/155.html

Only difference is that I need to pass more than 1 variable in one iteration.

2 REPLIES 2
Astounding
PROC Star

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.

Tom
Super User Tom
Super User

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);

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
  • 2 replies
  • 862 views
  • 0 likes
  • 3 in conversation