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
* identify variable having minimum value.

* This macro compares 3 or more variables and, for each case, it
	defines a variable containing the name of the variable(s) which
	has (have) the minimum value.

* code by Maciek Lobinski.

data list list /a b c d.
begin data
5 7 0 .
5 9 10 6
5 7 11 6
6 7 10 8
6 7 13 4
5 7 9 6
1 13 14 1
1 10 12 5
1 7 13 1
2 2 2 7
end data.
list.


define findmin (!positional= !charend('|')
 /poziom=!tokens(1))

!let !pusta=''.
!let !ciag=''.
recode !1 (0=sysmis).
string !poziom (a20).
!do !i !in (!1).
!let !ciag=!concat(!ciag,',',!i).
!doend.
compute #wyb__=min(!tail(!ciag)).
compute !poziom=' '.
!do !I !in (!1).
if (!I)=#wyb__ !poziom=concat(rtrim(!poziom),!quote(!I)).
!doend.
recode !poziom (''='PASS').
variable labels
!poziom !quote(!concat('Min of ',!1)).
freq !poziom.

!enddefine.


*example:.

set mprint=yes.
findmin a b c |poziom=newvar.
findmin a c d |poziom=newvar2.
set mprint=no.

******************************.
* Output of first macro call:

Min of a b c
 	 	Frequency	Percent	Valid Percent	Cumulative Percent	 
Valid	a	9	90.0	90.0	90.0	 
 	abc	1	10.0	10.0	100.0	 
 	Total	10	100.0	100.0	 	 


* Output of second macro call:
Min of a c d
 	 	Frequency	Percent	Valid Percent	Cumulative Percent	 
Valid	a	6	60.0	60.0	60.0	 
 	ac	1	10.0	10.0	70.0	 
 	ad	2	20.0	20.0	90.0	 
 	d	1	10.0	10.0	100.0	 
 	Total	10	100.0	100.0