1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
* QUESTION. I wonder if anyone can recommend software that will show a simple
	graphic of a distribution -- say, a histogram -- and also a
	highlighted point in the distribution.  I do employee satisfaction
	surveys and produce separate reports of job factor means for a variety
	of departments.  Currently, we give each department a simple printout
	that includes the overall company means on a variety of factors as
	well as the mean for the department.  It would be nice to graphically
	show in each report the company-wide distribution for each mean, as
	well as each department's place in the distribution, perhaps
	identified as an n-tile.

* ANSWER by rlevesque@videotron.ca posted to SPSS newsgroup on 2001/08/10.

SET MPRINT=yes.

*///////////////////// DEFINE MACRO /////////////////////////.
DEFINE !print(myvar=!TOKENS(1))

GRAPH  /HISTOGRAM=!myvar .

!DO !counter = 1 !TO !EVAL(!n).
COMPUTE mypct=0.
IF ($casenum=!counter) mypct=pct.
!LET !name=!EVAL(!CONCAT('!id',!counter))
!LET !title=!QUOTE(!CONCAT("Circle represents ",!name))
GRAPH
   /TEMPLATE="c:\\temp\\IdentifyYourOwnData.sct"
   /SCATTERPLOT(BIVAR)=!myvar WITH id BY mypct
   /MISSING=LISTWISE
   /TITLE=!title
   /FOOTNOTE='(mypct is the percentile)' .
!DOEND.

!ENDDEFINE.
*----------------------------END OF MACRO ----------------.

*////////////////////////////////////////////.
DEFINE !main (myvar=!TOKENS(1) /idname=!TOKENS(1))
RANK
  VARIABLES=!myvar  (A) /PERCENT INTO pct /N into n  /TIES=MEAN .
SORT CASES BY pct.
COMPUTE id=$CASENUM.

* The variable n created by the RANK above command contains the number of cases in the file.
* Write a macro which will give us the number of cases.
DO IF $CASENUM=1.
WRITE OUTFILE 'c:\\temp\\temp.sps' /"DEFINE !n()"n"!ENDDEFINE.".
END IF.
EXECUTE.

* Load the macro in memory.
INCLUDE FILE='c:\\temp\\temp.sps'.

* Define a macro which contains each id name.
STRING mac_name(A8).
COMPUTE mac_name=CONCAT('!id',LTRIM(STRING(id,F8.0)," "),"()").  
DO REPEAT r=1 TO !EVAL(!n).
+ DO IF id=r.
+ WRITE OUTFILE 'c:\\temp\\temp id names.sps' /"DEFINE "mac_name !idname"!ENDDEFINE.".
+ END IF.
END REPEAT.
EXECUTE.
INCLUDE 'c:\\temp\\temp id names.sps'.
!print myvar=!myvar.

!ENDDEFINE.
*////////////////////////////////////////////.

******* Example 1.
GET FILE='C:\\Program Files\\SPSS\\WORLD95.sav'.
* Since each case already represent summarized data, no pre-processing is required.
* Next line is just to reduce the length of the output.
N OF CASES 10.

* Call macros to show graph identifying the population density of each country.
!main myvar=density idname=country.

******* Example 2.
GET FILE='C:\\Program Files\\SPSS\\Employee data.sav'.

* Must first calculate mean salary by jobcat.
AGGREGATE
  /OUTFILE=*
  /BREAK=jobtime
  /salary = MEAN(salary).


* Call macros.
!main myvar=salary idname=jobtime.