Page 1 of 1

Looping through multiple arrays

Posted: Wed May 27, 2009 5:26 am
by abielr
I'm trying to loop through a group of series that I use to create graphs. For each graph I need the series name, a name for the graph object, and a string to use as the graph title. Example code is below.

Code: Select all

for %s %o %c regional::casatxa atlanta "Atlanta" regional::casboxa boston "Boston" graph gr{%o}.line @pcy({%s}) gr{%o}.addtext(t) {%c} next
My concern with this code is that my first line is going to get very long and unwieldy if I have dozens of series to loop through. Moreover, what if I later need to loop through just the series names? In this example they are not stored in a separate array, so I would have to retype them.

Is there a better approach? It seems ideal to be able to store each concept in its own array, and then loop through the arrays in parallel. Unfortunately I do not see any way of doing this in the documentation.

Thank you.

Re: Looping through multiple arrays

Posted: Wed May 27, 2009 8:03 am
by EViews Gareth
Best thing to do is to put the series into a group. Then loop through the number of series in the group, and grab the series name from the group one at a time:

Code: Select all

group g x y z for !i=1 to g.@count %name = g.@seriesname(!i) 'do stuff here next

Re: Looping through multiple arrays

Posted: Wed May 27, 2009 8:55 am
by abielr
I see how the group solution is useful for pre-existing series. However, in my example I have (a) pre-existing series (those items in the database), (b) strings not enclosed in quotes which are meant to be part of an object name, and (c) pure strings which are used as a title. I can imagine using a whole separate loop with (b) to build the series and add them to a group ahead of time, and another loop to create a table holding the titles (c), but at this stage there are so many extra loops that it isn't worth it.

Any thoughts?

Thanks very much.