How to fill the gap between two observations

Accepted Solution Solved
Reply
Contributor ZZB
Contributor
Posts: 43
Accepted Solution

How to fill the gap between two observations

[ Edited ]

How to replace the "missing value ." between 2000/01/02 and 2000/02/15 with the value "5" on 2000/01/01?

 

ID     DATE           Variable

01   2000/01/01         5

01   2000/01/02         .

01   2000/01/03         .

01   2000/01/04         .

01   2000/01/05         .

.................

01   2000/02/15         .

01   2000/02/16         7

 

Assuming that there are many ID like '01' and many case like missing value between 2000/01/02 and 2000/02/15. Is there any efficient way to replace these missing value with the most recently available value like '5' in this case before new value like '7' is available?


Accepted Solutions
Solution
‎01-07-2018 01:52 PM
PROC Star
Posts: 1,075

Re: How to fill the gap between two observations

data have;
input ID$ DATE:yymmdd10. Variable;
format DATE yymmdd10.;
datalines;
01 2000/01/01 5
01 2000/01/02 .
01 2000/01/03 .
01 2000/01/04 .
01 2000/01/05 .
01 2000/02/15 .
01 2000/02/16 7
;

data want;
   update have(obs=0) have;
   by ID;
   output;
run;

View solution in original post


All Replies
Solution
‎01-07-2018 01:52 PM
PROC Star
Posts: 1,075

Re: How to fill the gap between two observations

data have;
input ID$ DATE:yymmdd10. Variable;
format DATE yymmdd10.;
datalines;
01 2000/01/01 5
01 2000/01/02 .
01 2000/01/03 .
01 2000/01/04 .
01 2000/01/05 .
01 2000/02/15 .
01 2000/02/16 7
;

data want;
   update have(obs=0) have;
   by ID;
   output;
run;
Trusted Advisor
Posts: 1,149

Re: How to fill the gap between two observations

You'll find the answer to the antecedent to this topic in How to merge daily and quarterly dataset

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 144 views
  • 3 likes
  • 3 in conversation