I have this dataset which contains data only for the weekdays. Here is how it looks like:
ID Name Some Val Other Val Date
10 Somebody 33001.93 33001.93 2018-10-01
10 Somebody 33481.93 33481.93 2018-10-02
10 Somebody 33001.93 33001.93 2018-10-03
10 Somebody 33582.76 33582.76 2018-10-04
10 Somebody 33582.73 33582.79 2018-10-05
10 Somebody 33582.76 33582.76 2018-10-08
10 Somebody 33342.76 33342.76 2018-10-09
10 Somebody 33462.76 33462.76 2018-10-10
My computation requires the data to be populated for all the days in a month. To make the data usable, I need to populate the data for the weekends as well.
In the above data sample, the missing records for the dates 2018-10-06 and 2018-10-7 needs to be replicated by last available value (2018-10-05) in this case. So that the resultant dataset, after the transformation looks like:
ID Name Some Val Other Val Date
10 Somebody 33001.93 33001.93 2018-10-01
10 Somebody 33481.93 33481.93 2018-10-02
10 Somebody 33001.93 33001.93 2018-10-03
10 Somebody 33582.76 33582.76 2018-10-04
10 Somebody 33582.73 33582.79 2018-10-05
10 Somebody 33582.73 33582.79 2018-10-06
10 Somebody 33582.73 33582.79 2018-10-07
10 Somebody 33582.76 33582.76 2018-10-08
10 Somebody 33342.76 33342.76 2018-10-09
10 Somebody 33462.76 33462.76 2018-10-10
I am looking for guidance on how to retain the missing record, loop through all the available rows and insert row wherever it's missing. I am thinking for creating a lookup table which contains all the date values, merge them and wherever there is no match, I need to insert the last available value.
My experience in SQL is limited and coming from SAS background, I can possibly accomplish this using macros. I am totally stuck on how to attack this problem in SQL.
Need guidance me on how to proceed.