BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sunny_Sun
Calcite | Level 5

Hi,

I have a huge data with a lot of missing values for a variable.  For example,

Data a;

     input x y;

     cards;

1 1

1 0

1 .

1 .

2 2

2 3

2 9

2 .

2 .

;

run;

Now I want to fill in the missing y with its lagged value. That is, for x=1, y=0 for the missing ones and x=2, y=9 for the last two observations. But when I use lag function, it only fills in the first missing observation.

Can anyone please tell me how to do this? Please note, the data is large. So it's better to avoid open/close data too many times.

Thanks,

Sunny

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

data want(drop=y rename=(y1=y));

set a;

retain y1;

if y>. then y1=y;

run;

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

It is probably simpler than you thought with UPDATE processing:

data want;

update a(obs=0) a;

by x;

output;

run;

PG

PG
stat_sas
Ammonite | Level 13

data want(drop=y rename=(y1=y));

set a;

retain y1;

if y>. then y1=y;

run;

jakarman
Barite | Level 11

The lag function in SAS is a queue functionality and is quite different then the lag en lead functions in Oracle / MS-Sql

For not getting confused avoid using that same name for that.

What you are possible trying to do is known as "impute missings"  as that is part of the mining steps.

Just putting in the previous value is not the best strategy to do that, there are several more approaches .

---->-- ja karman --<-----
Sunny_Sun
Calcite | Level 5

Many thanks all of you!

Thanks,

Sunny

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 2035 views
  • 6 likes
  • 4 in conversation