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
* QUESTION: data were entered with "blank cells" meaning "same data as line above". 
	How can I replace these blank cells by the correct data?

* ANSWER posted to SPSSX-L on 2001/08/09 by rlevesque@videotron.ca.

* Notes: 
*	1. "blank" cells are Missing values in case of numeric variables but they are 
	indeed "blank cells" in case of string variables. The following solution works for
	any combination of numeric and string variables and any number of variables. 
*	2. Of course the solution assumes that "blank" cells are the only "missing values".

* Create a dummy data file for illustration purposes.
DATA LIST LIST /locat(F8.0) gender(A1) agegroup(F8.0) data1(F8.0) data2(F8.0).
BEGIN DATA
1 M 30 2 5 
.  " " 35 3 7
. F 30 3 3 
. " " 35 5 5
END DATA.
LIST. 

* Start the job.
* The next line is too avoid seeing a lot of irrelevant error messages in the output window.
SET ERRORS=no.

DO REPEAT var=ALL.
* Next line produces an irrelevant error message for string variables.
IF MISSING(var) var=LAG(var).
* Next line produces an irrelevant error message for numeric variables.
IF LEN(LTRIM(var))=0 var=LAG(var).
END REPEAT PRINT.

* Reset error messages.
SET ERRORS=yes.

LIST.