DATA Step, Macro, Functions and more

Retaining the previous value

Reply
N/A
Posts: 0

Retaining the previous value

i have the data set like this now i wnat the previous obs repeated if the total is '.'



id age tot
1 23 9
2 23 .
3 9 .
4 10 5
3 8 .
6 7 .
5 8 1
4 3 .
2 8 .
1 6 3
3 4 .



ouput

id age tot
1 23 9
2 23 9
3 9 9
4 10 5
3 8 5
6 7 5
5 8 1
4 3 1
2 8 1
1 6 3
3 4 3


in this if the total is '.' then the previous value shd come there
SAS Employee
Posts: 174

Re: Retaining the previous value

Posted in reply to deleted_user
This is one way of doing it :-)

data input;
input id age tot;
datalines;
1 23 9
2 23 .
3 9 .
4 10 5
3 8 .
6 7 .
5 8 1
4 3 .
2 8 .
1 6 3
3 4 .
;
run;
data output;
set input;
retain new_tot;
if tot > . then new_tot=tot;
run;
N/A
Posts: 0

Re: Retaining the previous value

Posted in reply to GertNissen
thqs got it
Ask a Question
Discussion stats
  • 2 replies
  • 139 views
  • 0 likes
  • 2 in conversation