I have to generate al lot of graphs of one variable and thought it would be easier using a macro.

Basically there are 3 parameters to base the graphs on:

1. The variable is observed for 6 years, so the first parameter is the year: <year>

2. The grouping variable on the x-axis: <groupvar>

3. The type of statistic, e.g. MEAN or SUM: <stat>

I want to able to generate all possible combinations of 1-3. I.e., for each grouping variable I want combinations of years and stats. Therefore, I thought nested loops would do the trick:

Code: Select all

```
SET MPRINT=no.
define graphs (year=!cmdend /groupvar=!cmdend /stat=!cmdend)
!DO !gr !IN (!groupvar)
!DO !yr !IN (!year)
!DO !st !IN (!stat)
GRAPH
/BAR(SIMPLE)=!st(!concat('varname_', !yr)) BY !gr.
!DOEND
!DOEND
!DOEND .
!enddefine .
* Call the macro .
SET MPRINT=yes.
graphs year=2006 2007 2008 2009 groupvar=groupvar1 groupvar2 stat=SUM MEAN.
```

Code: Select all

```
SET MPRINT=no.
60 0 M> SET MPRINT=no.
define graphs (year=!cmdend /groupvar=!cmdend /stat=!cmdend)
!DO !gr !IN (!groupvar)
!DO !yr !IN (!year)
!DO !st !IN (!stat)
GRAPH
/BAR(SIMPLE)=!st(!concat('varname_', !yr)) BY !gr.
!DOEND
!DOEND
!DOEND .
!enddefine .
* Call the macro .
SET MPRINT=yes.
graphs year=2006 2007 2008 2009 groupvar=groupvar1 groupvar2 stat=SUM MEAN.
78 0 M>
79 0 M> .
80 0 M>
81 0 M> .
```

Thanks a bunch!

EDIT: moved post to correct forum