SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Fillng in Missing Values based on previous observations

Reply
Occasional Contributor
Posts: 13

Fillng in Missing Values based on previous observations

I need to replace missing values in my data set. I need SAS to reference the previous observation and calculate the date of the current observation based on the previous observation.

 


data Example; set Example1;
If Date = "." then do;
Date = Obs - 1 ....... Date+1;
Run;

 

Thanks.

Occasional Contributor
Posts: 19

Re: Fillng in Missing Values based on previous observations

Hi

 

There is a LAG function in SAS that allows you to reference the value of a variable on the previous observation.

 

It is well documented and works along the lines of

 

If date = . then date = lag(date) + 1;

 

Cheers

 

Chris

Respected Advisor
Posts: 4,659

Re: Fillng in Missing Values based on previous observations

Use a retained variable:

 

data want;
retain previousDate;
set have;
date = coalesce(date, intnx("DAY", previousDate, 1));
previousDate = date;
drop previousDate;
run;
PG
Ask a Question
Discussion stats
  • 2 replies
  • 210 views
  • 0 likes
  • 3 in conversation