BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MBI
Calcite | Level 5 MBI
Calcite | Level 5
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
1 ACCEPTED SOLUTION

Accepted Solutions
Olivier
Pyrite | Level 9

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

7 REPLIES 7
Olivier
Pyrite | Level 9

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

njvelandia
Calcite | Level 5

Excellent

Nieves
Quartz | Level 8

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!

apaez062
Fluorite | Level 6

Hi Nieves,

 

I am having the same problem right now where the value that I want pasted to all other records within each group is always the last...not the first. Did you ever get a solution to your question?

 

If so, could you forward that solution to me? I desperately need it.

 

Thank you!

TomKari
Onyx | Level 15

Just sort your data in reverse order, so the value you want is at the top. Once you've rippled your value, resort into the original sequence.

 

Tom

MBI
Calcite | Level 5 MBI
Calcite | Level 5
Ah, perfect! Easier than I thought. Thank you!!
jelanseward
Calcite | Level 5

AMAZING 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 36719 views
  • 13 likes
  • 7 in conversation