I have a problem that I was not able to find a solution for on Stackoverflow or elsewhere and I am not sure, if it is possible do solve with SAS proc sql.

My aim is to produce a view (z) based on a dataset (a) and a view (b). The problem ist that (a) can be updated to the actual year at the beginning of the year, while (b) can only be updated later in the year. Nevertheless I want my view (z) to produce data at the beginning of the year (even if it is provisionally), what is naturally only possible if there is data available from both the (a) and (b). So what I want is that view (z) uses the latest available year from (b) and use it as if it would be the actual year (so basically to impute data into (b) for the latest data year in (a). I tried to do this with the following code, but it did not work exactly the way I want it:

```
proc sql;
create view x1 as 
   select ste.jahr, ste.gnr, ste.einwg, stk.stkabs
      from           d18.fg_gji_steinh as ste
                           inner join 
                        d18.fg_gji_skraft as stk
                                    on 
                        case when exists (select stkabs from d18.fg_gji_skraft where ste.jahr=stk.jahr)
                        then ste.jahr=stk.jahr and ste.gnr=stk.gnr
                        else input(ste.jahr,4.)=input(stk.jahr,4.)+1 and ste.gnr=stk.gnr
                        end 
                        order by ste.jahr, ste.gnr ;   
quit;

```

It produces the expected data in the first and the last year, but not in the years between as it produces there two rows for one observation. The first observation contains data from the actual year, the other observation contains data from the last year. 

Has anyone an idea how to solve this problem?