the "Draft Viewer" (the legacy type as Microsoft would say)
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.
Many solutions posted to newsgroups or to SPSS AnswerNet start with something like
DATA LIST LIST /a b c.
BEGIN DATA
1 2 3
4 1 5
END DATA.
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:
Step
How?
select the entire solution, copy it
Control C to copy, Control V to paste
paste it in an empty Syntax window and
To open a new Syntax Window, use the menu: File>New>Syntax (or
click on button 2).
run it.
Using the menu of Syntax Window: Run>All (or
click on button 16).
When you see "Pending transformation" in the status bar, add an EXECUTE
command at the end of your syntax than run that line or click on button 21.
In some cases, there was an error and you do not want to run the
Pending transformation because there is no point having the processor go through a large
data file for example. In such case, either enter CLEAR TRANSFORMATION. in the syntax
window and run it.
First, do not complain the next day about this situation... Instead, ask yourself
whether the question was sufficiently clear to permit somebody to give you the answer
without having to cover 3-4 possible scenarios? After 3 - 4 days, send a new email
restating the problem; try to give additional information or describe the problem from a
different angle.
Questions which start by something like
"I am desperate, I must remit my term paper tomorrow" or
"I do not have time to do this macro, could somebody do it for me?"
If you receive directly by email a correct answer to a question you posted, do forward a
copy of the answer to the list. This avoids having other people loose time developing a
solution.
Reply to the list as opposed to only by email to the person asking the question.
Be polite, although there are many persons giving time to help others, they do not
"owe" you anything.
Ask only questions related to the purpose of the mailing list or newsgroup. Do not ask
an Excel or Word question in an SPSS list unless it is directly related to import from or
export to SPSS.
Don't blast somebody on the list because the answer was wrong or it does not do what you
wanted (maybe it does what you wrote it should do...).
If you think somebody made a big mistake, consider sending a private email to the author
pointing out the issue. If you are right, this will give the author the
chance to correct himself by issuing a second post to the list (or newsgroup) and you will
have a new friend. On the other hand, if you are wrong you will have
avoided a very embarrassing situation. :-)
Don't start "Holy Wars", statistics is a science in evolution and there are
room for diverging opinions on many issues.
When asking a question on a newsgroup (as opposed to a mailing list),do not request that
the answer be sent to you by email as opposed as to the newsgroup.
It is not considered "polite" to have an attachment to a postings to a mailing
list. In some countries internet service is both slow and expensive. Attachments can also
contain viruses.
The original question
The posted answer
The notes explaining how to use the macro
The original question
I 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 above method is ok if you need to do other things between the printing of the
charts.
* The following macro is ok if all you need is to print the bar charts and the same min
number of cases is required..
SET MPRINT=no.
*////////////////////.
DEFINE !chart2 (minnb=!TOKENS(1) /cats=!CMDEND)
/* minnb = minimum number of cases required in order to chart category value*/.
/* cats = names of the categorical variables to be charted*/.
COMPUTE dummy=1.
!DO !cat !IN (!cats)
FILTER OFF.
* Sorting is necessary for the MATCH FILES command.
SORT CASES BY !cat.
!LET !fname=!QUOTE(!CONCAT('C:\temp\',!cat,'.SAV'))
AGGREGATE
/OUTFILE=!fname
/PRESORTED
/BREAK=!cat
/nb = N(dummy).
MATCH FILES /FILE=*
/TABLE=!fname
/BY !cat.
FREQUENCY VARIABLES=!cat.
LIST.
COMPUTE flag=(nb>=!minnb).
FILTER BY flag.
GRAPH
/BAR(SIMPLE)=COUNT BY !cat
/MISSING=REPORT.
* Delete the variable nb.
MATCH FILES FILE=* /DROP=nb.
!DOEND
* Delete the variable dummy.
MATCH FILES FILE=* /DROP=dummy.
!ENDDEFINE.
*///////////////////
SET MPRINT=yes.
!chart2 minnb=5 cats= age prog year.
EXECUTE.
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
!ENDDEFINE.
*////////////////////.
SET MPRINT=yes.
!chart minnb=5 cat=age.
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
line
!chart minnb=5 cat=age.
by the following 3 lines:
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
!chart minnb=10 cat=region.
!chart minnb=10 cat=climate.
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
and call it using the line
!chart minnb=10 cat=age climate region.