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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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