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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

5 REPLIES 5
Astounding
PROC Star

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;

apolitical
Obsidian | Level 7

Astoundingly simple solution. Thanks!

ChrisNZ
Tourmaline | Level 20

This looks like homework, What have you tried?

apolitical
Obsidian | Level 7

Unfortunately this is not homework and there is no buddy to copy from...

ChrisNZ
Tourmaline | Level 20

@Astounding's code is the answer.

 

You can even shorten it slightly.

 

if last.id then do period = period + 1 to 5;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1220 views
  • 0 likes
  • 3 in conversation