Date | Maturity | Rate |
01-Mar | 1 | 5 |
01-Mar | 2 | 6 |
01-Mar | 3 | |
01-Mar | 4 | 8 |
01-Mar | 5 | |
02-Mar | 1 | |
02-Mar | 2 | 11 |
02-Mar | 3 | 12 |
02-Mar | 4 | 13 |
02-Mar | 5 | 14 |
03-Mar | 1 | 20 |
03-Mar | 2 | 21 |
03-Mar | 3 | 22 |
03-Mar | 4 | |
03-Mar | 5 |
I wish to interpret the missing values of "rate" based on the known values of "maturity" and "rate". As you can see, data is divided into different groups by date. What I want is interpolation by different groups (date).
Output should be:
Date | Maturity | Rate |
01-Mar | 1 | 5 |
01-Mar | 2 | 6 |
01-Mar | 3 | 7 |
01-Mar | 4 | 8 |
01-Mar | 5 | 9 |
02-Mar | 1 | 10 |
02-Mar | 2 | 11 |
02-Mar | 3 | 12 |
02-Mar | 4 | 13 |
02-Mar | 5 | 14 |
03-Mar | 1 | 20 |
03-Mar | 2 | 21 |
03-Mar | 3 | 22 |
03-Mar | 4 | 23 |
03-Mar | 5 | 24 |
Thanks in advance 🙂
If you have a SAS/ETS license, this is by far the easiest
data have;
input Date $ Maturity Rate;
infile datalines missover;
datalines;
01-Mar 1 5
01-Mar 2 6
01-Mar 3
01-Mar 4 8
01-Mar 5
02-Mar 1
02-Mar 2 11
02-Mar 3 12
02-Mar 4 13
02-Mar 5 14
03-Mar 1 20
03-Mar 2 21
03-Mar 3 22
03-Mar 4
03-Mar 5
;
proc expand data=have out=want extrapolate;
convert Rate=Rate / method=join ;
by Date;
id Maturity;
run;
Result:
Date Maturity Rate 01-Mar 1 5 01-Mar 2 6 01-Mar 3 7 01-Mar 4 8 01-Mar 5 9 02-Mar 1 10 02-Mar 2 11 02-Mar 3 12 02-Mar 4 13 02-Mar 5 14 03-Mar 1 20 03-Mar 2 21 03-Mar 3 22 03-Mar 4 23 03-Mar 5 24
data have;
input Date $ Maturity Rate;
cards;
01-Mar 1 5
01-Mar 2 6
01-Mar 3 .
01-Mar 4 8
01-Mar 5 .
02-Mar 1 .
02-Mar 2 11
02-Mar 3 12
02-Mar 4 13
02-Mar 5 14
03-Mar 1 20
03-Mar 2 21
03-Mar 3 22
03-Mar 4 .
03-Mar 5 .
;
data want;
set have;
retain r;
if not missing(rate) then r=rate;
else do;
rate=r+1;
r=rate;
end;
drop r;
run;
If you have a SAS/ETS license, this is by far the easiest
data have;
input Date $ Maturity Rate;
infile datalines missover;
datalines;
01-Mar 1 5
01-Mar 2 6
01-Mar 3
01-Mar 4 8
01-Mar 5
02-Mar 1
02-Mar 2 11
02-Mar 3 12
02-Mar 4 13
02-Mar 5 14
03-Mar 1 20
03-Mar 2 21
03-Mar 3 22
03-Mar 4
03-Mar 5
;
proc expand data=have out=want extrapolate;
convert Rate=Rate / method=join ;
by Date;
id Maturity;
run;
Result:
Date Maturity Rate 01-Mar 1 5 01-Mar 2 6 01-Mar 3 7 01-Mar 4 8 01-Mar 5 9 02-Mar 1 10 02-Mar 2 11 02-Mar 3 12 02-Mar 4 13 02-Mar 5 14 03-Mar 1 20 03-Mar 2 21 03-Mar 3 22 03-Mar 4 23 03-Mar 5 24
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.