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
* QUESTION: How can I change ALL numeric variables in my file as follows: I want to round all 
* variables to the nearest integer and use the format F8.0.

* Solution by Ray.

DATA LIST LIST /g(F8.2) x345(F8.2) str1(A8) v3(F8.2) b(F8.2) k(F8.2).
BEGIN DATA.
1.21 2.49 "green" 3.01 5.51 41.98
2.33 5.67 "blue" 1.75 4.22 6.02
END DATA.

* The string variables will produce error messages because their value cannot be "rounded".
* To avoid seeing these error messages, they are temporarily turned off.
SET ERRORS=off.
DO REPEAT v=ALL.
+ COMPUTE v=RND(v).
+ FORMATS v(F8.0).
END REPEAT.
SET ERRORS=on.
EXECUTE.

* Example, if you wanted to change only a subset of variables. you could use.

*DO REPEAT v=x345 TO b.
*instead of 
*DO REPEAT v=ALL.