I have this table
ID Period Value
A 1 10
A 2 50
A 3 30
B 1 20
B 2 50
I want to make a table that extends for each ID to period 5, filling the previously non-existent values with the last existing value. Like this.
ID Period Value
A 1 10
A 2 50
A 3 30
A 4 30
A 5 30
B 1 20
B 2 50
B 3 50
B 4 50
B 5 50
In the existing table, the last period could be different. How do I program this? Thanks.
It should be straightforward as long as your data set is sorted:
data want;
set have;
by id period;
output;
if last.id and period < 5 then do period = period + 1 to 5;
output;
end;
run;
It should be straightforward as long as your data set is sorted:
data want;
set have;
by id period;
output;
if last.id and period < 5 then do period = period + 1 to 5;
output;
end;
run;
Astoundingly simple solution. Thanks!
This looks like homework, What have you tried?
Unfortunately this is not homework and there is no buddy to copy from...
@Astounding's code is the answer.
You can even shorten it slightly.
if last.id then do period = period + 1 to 5;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.