Desktop productivity for business analysts and programmers

How do I "fill down" in a table?

Accepted Solution Solved
Reply
Occasional Contributor MBI
Occasional Contributor
Posts: 19
Accepted Solution

How do I "fill down" in a table?

Hi all,
I have what I think is a relatively easy quesiton but I can't figure it out. I'm trying to make the following data table:

1
.
.
2
.
.
.
3
.
.

look like this:

1
1
1
2
2
2
2
3
3
3

essentially all I'm trying to do is to 'fill down' the null variables with the one above it. Is there an easy way to do this?

Thanks!

MBI

Accepted Solutions
Solution
‎11-04-2016 07:42 AM
Super Contributor
Posts: 260

Re: How do I "fill down" in a table?

[ Edited ]

Hi MBI.
I'm afraid you can only do that programmatically. Here is some sample code : let's say you have a dataset called MyData, and a variable (column) called X.

DATA myDataFilled (DROP = filledX) ;
SET myData ;
RETAIN filledX ; /* keeps the last non-missing value in memory */
IF NOT MISSING(X) THEN filledX = X ; /* fills the new variable with non-missing value */
X = filledX ;
RUN ;



Regards.
Olivier

View solution in original post


All Replies
Solution
‎11-04-2016 07:42 AM
Super Contributor
Posts: 260

Re: How do I "fill down" in a table?

[ Edited ]

Hi MBI.
I'm afraid you can only do that programmatically. Here is some sample code : let's say you have a dataset called MyData, and a variable (column) called X.

DATA myDataFilled (DROP = filledX) ;
SET myData ;
RETAIN filledX ; /* keeps the last non-missing value in memory */
IF NOT MISSING(X) THEN filledX = X ; /* fills the new variable with non-missing value */
X = filledX ;
RUN ;



Regards.
Olivier

New User
Posts: 1

Re: How do I "fill down" in a table?

Excellent

Occasional Contributor
Posts: 15

Re: How do I "fill down" in a table?

[ Edited ]

Hello @Olivier

 

may I ask what if the non missing value does not appear as the first observation? How to fill in the table in the following case?

grouptimevalue
1Jan.
1Feb10
1Mar.
2Jan.
2Feb.
2Mar20
3Jan30
3Feb.
3Mar.
4Jan.
4Feb40
4Mar.
5Jan50
5Feb.
5Mar.

and I want the data to be filled in as follows:

grouptimevalue
1Jan10
1Feb10
1Mar10
2Jan20
2Feb20
2Mar20
3Jan30
3Feb30
3Mar30
4Jan40
4Feb40
4Mar40
5Jan50
5Feb50
5Mar50

 

 

Thank you!

Occasional Contributor MBI
Occasional Contributor
Posts: 19

Re: How do I "fill down" in a table?

Ah, perfect! Easier than I thought. Thank you!!
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 8969 views
  • 4 likes
  • 4 in conversation