arraysdatesasreverse-engineeringdo-loops

How to reverse engineer missing dates in SAS dataset


I am trying to reverse engineer some data for a dataset that is only updated weekly, which I want to be daily. What I want is a dataset that is at the fips-day level where the missing days are filled in. For instance we may only have 2022-03-03 and 2022-03-10, but I want a new column (at the fips-day level) where each rate is 1/7th of the rate present in the cell in which we DO have data.

data fips_date;
    input fips $ date :yymmdd10. rate;
    format date ddmmyy10.;
    datalines;
    00065 2022-03-03 30.2
    00066 2022-03-03 23.4
    00067 2022-03-03 14.1
    00065 2022-03-10 28.4
    00066 2022-03-10 21.8
    00067 2022-03-10 15.3
run;

What I want the result to look like is below (original date rows highlighted), however I am a novice SAS user and don't know how to get there. I imagine it would need to be a do-loop or an array of sorts that can be grouped or performed at the fips-date level.

Desired Output Format

Thank you for any advice or code you may be able to share!


Solution

  • data want;
       set fips_date;
       do date = date - 6 to date;
          daily_rate = rate / 7;
          output;
       end;
    run;