Replace Missing variable values with non-blank value

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

lb.fam
Posts: 1
Joined: Fri Dec 11, 2015 11:14 pm

Replace Missing variable values with non-blank value

Postby lb.fam » Fri Dec 11, 2015 11:26 pm

Hi,

I have data in the form:

+----------+--------+-------+
| House#| Name| Age|
+----------+--------+-------+
| 1 | John| 20 |
| | Jill | 23 |
| 2 | Mary | 50 |
| | Todd | 5 |
| | Alex | 6 |
| 3 | Bob | 35 |
+----------+--------+-------+

I wish to replace the blanks with the first non blank value found above it to obtain:

+----------+--------+-------+
| House#| Name| Age|
+----------+--------+-------+
| 1 | John| 20 |
| 1 | Jill | 23 |
| 2 | Mary | 50 |
| 2 | Todd | 5 |
| 2 | Alex | 6 |
| 3 | Bob | 35 |
+----------+--------+-------+

1. Is there a way to use the point and click interface to achieve this?

2. Found two articles to do this:

http://spsstools.net/en/syntax/651/

http://stackoverflow.com/questions/1642 ... ue-sas-9-3


but one says don't use LAG, the other uses LAG. Which method is correct?
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Replace Missing variable values with non-blank value

Postby GerineL » Mon Dec 14, 2015 9:00 am

both could work, just try it and see if it gets you the result you want.
gmckenna
Posts: 4
Joined: Wed Feb 08, 2012 12:28 pm

Re: Replace Missing variable values with non-blank value

Postby gmckenna » Thu Sep 15, 2016 2:05 pm

I am trying to perform the same "replace missing variable" as described above. However, the syntax options do not seem to work for me. I should also point out that I want to restrict the "replacement" to the first variable, which in my case is user ID. I am using version 22. Any other suggestions?
JonPedersen
Posts: 117
Joined: Wed May 25, 2011 7:07 am
Contact:

Re: Replace Missing variable values with non-blank value

Postby JonPedersen » Tue Sep 20, 2016 8:24 am

Hi,
Basically, the first reference you found is correct, the second pertains to SAS, and SAS and SPSS lag functions behave differently (and SPSS does not have Retain).
The code you need is:

Code: Select all

if missing(House#) House#=lag(House#).
execute.
can be done with point and click, but that would just be using transform and compute variable to achieve the same code. Very tedious.
hth
Jon

Who is online

Users browsing this forum: No registered users and 1 guest

cron