SPSS Newbie's Corner (note that this is based on version 10.07)
There are 2 types of Output Windows:
I always use the Viewer because of the added flexibility regarding editing graphs and pivoting Pivot Tables. The choice of Output is made using the menu: Edit > Options and clicking the General Tab. In the "Output Type at Start-up" box, click Viewer.
I find it very useful to have a log of the syntax in the Output window. To have the log, using the menu: Edit > Options and click the Viewer Tab. Select the "Display commands in the log" in the lower left corner. You will see in the next bullet why this is a good idea.
See Learning Syntax
Many solutions posted to newsgroups or to SPSS AnswerNet start with something like
The purpose of the lines above is to create a data file (that is to insert data in the data editor). This allows the syntax which follows that code to run. Without data, syntax cannot work its magic ;-)
So when you see solutions which start with "DATA LIST" of "INPUT PROGRAM", do the following:
This topic has 3 sections:
The original question
The original questionI am creating a large number of bar charts. For each chart I must exclude any categories that have fewer than 10 students. I have been running frequencies and then manually clicking on each category that was to be omitted, but I know there must be a better way. Any ideas would be greatly appreciated.
The posted answer
DATA LIST LIST /age prog year.
* The above method is ok if you need to do other things between the printing of the
* The following macro is ok if all you need is to print the bar charts and the same min number of cases is required..
* Delete the variable dummy.
The notes explaining how to use the macro
For simplicity I will only cover the first macro (the name of the macro is !chart). (The same process would be followed to use the second macro).
1. Start SPSS
2. Open (Load) your data file using the menu: File>Open>Data
3. Open a Syntax Window using the menu: File>New>Syntax
4. Select the syntax for the !chart macro and paste it in the Syntax Window.
This is the portion of the posted answer which starts with
and ends with
5. Comments: The macro ends with the !ENDDEFINE. command; the SET MPRINT=yes is just to allow you to view the code in the Output window.
The line "!chart minnb=5 cat=age" calls the macro. The line means: do a chart using the variable age, exclude from the graph any age at which there are less than 5 persons.
6. Suppose that one of the categorical variable in you data file is
language and that you want to exclude language with less than 10 persons, then replace the
7. Note: The above COMPUTE line is 2 lines above the DEFINE command in the posted answer.
8. Now comes the magic moment, you are ready to run the macro. To do so, use the menu: Run>All
9. Check the output window, the chart should be there.
10. If you need to do charts for variables language, region, climate.
You can add the following 2 new lines
11. Comments: the macro !chart allows you to vary the minimum number of required cases for each variable.
12. If the charts of many variables require the same number of minimum
cases, you can use the macro !chart2
The macro chart2 is fully commented here.
Syntax Reference Guide (a good buy)
This page was last updated on April 10, 2002. Raynald's SPSS Tools
© Raynald Levesque 2001-04