Newbie's Corner
Home Up

Enter keywords


Exact match


Advanced Search
Feedback
Site Map

 

Other languages
Deutsch
Español
Français
Italiano
Português

 

Do you love this site?

 

SPSS Newbie's Corner (note that this is based on version 10.07)

  1. Which type of Output Window should I use?
  2. Keep the log!
  3. How do I start learning syntax?
  4. What does DATA LIST LIST /a b c mean?
  5. Pending Transformation (how to get rid of them)
  6. How come nobody answered my question?
  7. Netiquette (how to "behave" on internet)
  8. Somebody posted a macro but I do not know how to use it
  9. Why can't I just use Excel to do my statistical analysis?
    See U. of Massachusetts - Using Excel 7 for Statistical Analysis (Successes and Cautions)
    and Use of Excel for Statistical Analysis by AgResearch Ruakura, Hamilton, New Zealand

 

Which type of Output Window should I use?

There are 2 types of Output Windows:

  1. the "Viewer" (the modern way) and
  2. 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.

 

Keep the log!

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.

 

How do I start learning syntax?

See Learning Syntax

 

What does DATA LIST LIST /a b c mean?

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

 

Pending Transformation

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.

 

How come nobody answered my question?

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?"

are not likely to draw much sympathy.

 

Netiquette

Do  Do  Do

  1. 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.
  2. Reply to the list as opposed to only by email to the person asking the question.
  3. Be polite, although there are many persons giving time to help others, they do not "owe" you anything.
  4. 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  Don't  Don't

  1. 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. :-)
  2. Don't start "Holy Wars", statistics is a science in evolution and there are room for diverging opinions on many issues.
  3. 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.
  4. 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.

 

Somebody posted a macro but I do not know how to use it

This topic has 3 sections:

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 posted answer

DATA LIST LIST /age prog year.
BEGIN DATA
25 1 2
25 1 2
25 1 2
25 1 2
25 1 4
25 1 4
25 1 4
25 1 4
25 1 4
25 1 4
25 1 7
25 1 7
25 1 7
25 1 7
25 1 2
26 1 2
27 2 1
27 2 1
27 2 1
27 2 1
27 2 1
27 2 1
END DATA.
COMPUTE dummy=1.
SET MPRINT=no.

*////////////////////.
DEFINE !chart (minnb=!TOKENS(1) /cat=!TOKENS(1))
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.
COMPUTE flag=(nb>=!minnb).
FILTER BY flag.
GRAPH
    /BAR(SIMPLE)=COUNT BY !cat
    /MISSING=REPORT.
* Delete the variable nb.
MATCH FILES FILE=* /DROP=nb.
!ENDDEFINE.
*////////////////////.

SET MPRINT=yes.
!chart minnb=5 cat=age.
!chart minnb=6 cat=prog.
!chart minnb=5 cat=year.

* 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

*////////////////////.
DEFINE !chart (minnb=!TOKENS(1) /cat=!TOKENS(1))

and ends 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:

COMPUTE dummy=1.
!chart minnb=10 cat=language.
EXECUTE.

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.

The macro chart2 is fully commented here.

Syntax Reference Guide (a good buy)

AddFreeStats.com Free Web Stats in real-time !

 

 

This page was last updated on April 10, 2002.  Raynald's SPSS Tools

© Raynald Levesque 2001-04