BookmarkSubscribeRSS Feed
Steve1964
Obsidian | Level 7

ID statement with invterval=option are often used in many SAS/ETS procedures and the variable in ID statement is the same as that in interval= option in most cases, which makes me wonder what's the function of  ID statement and ID variable. 

  I give an example here to illustrate the question.

First generate data set yield containing date and the returns of five different terns

data yield;
input year yymmdd10. r1 r2 r3;
format year yymmdd10.;
datalines;
2006/1/6	1.46294753	1.545676434	1.9558192	2.162519237	2.194832429
2006/1/13	1.517894442	1.549327787	1.669094293	1.988184834	2.221032995
2006/1/20	1.443779686	1.510635118	1.723018	1.943191704	2.204235341
2006/2/10	1.435783602	1.688414215	1.69724586	2.151445183	2.201574693
2006/2/17	1.6281019	1.817423293	1.680777269	2.163502995	2.260976889
2006/2/24	1.829734545	1.777889515	1.775476292	2.231772981	2.452023801
2006/3/3	1.75221336	1.845058223	1.806409006	2.133990918	2.241448065
2006/3/10	1.313178054	1.487231308	1.843614505	2.162158776	2.202237333
2006/3/17	1.627393859	1.714023033	1.975522236	2.218210508	2.187701008
2006/3/24	1.619900094	1.728668273	2.214861743	2.357222001	2.3055817
2006/3/31	1.691377603	1.850381878	2.132324347	2.341794321	2.593702564
2006/4/7	1.231735136	1.807453577	2.164653658	2.410393618	2.388405978
2006/4/14	1.449047203	1.713296575	2.294770498	2.474280203	2.667311041
2006/4/21	1.480894013	1.629524198	2.285539957	2.533601373	2.524863995
2006/4/28	1.141625772	1.789791092	2.161464221	2.340933419	2.457365711
2006/5/12	1.307451441	1.81715313	2.038693946	2.267437591	2.394994933
2006/5/19	1.439636654	2.080794775	2.108766763	2.313459556	2.4577652
2006/5/26	1.674160206	1.765928425	2.25844977	2.528455213	2.693901836
2006/6/2	1.482448956	2.21148808	2.349679345	2.507319142	2.804667556
2006/6/9	1.752021548	2.28769497	2.728398265	2.783386524	2.89890221
2006/6/16	2.209143133	2.209143133	2.290172298	2.549907972	2.827645284
2006/6/23	2.192305499	2.192305499	2.538649928	2.817736518	2.893188672
2006/6/30	1.357508534	2.232876297	2.459028163	2.486074859	2.729804656
2006/7/7	1.378897552	2.119779823	2.491028121	2.548943541	2.750352417
2006/7/14	1.284483937	2.210362629	2.674652884	2.714931149	2.762746862
2006/7/21	1.904280164	1.972541129	2.582892905	2.544756038	2.729714013
2006/7/28	1.826223252	1.985150783	2.562360161	2.591627008	2.757583994
;

Then employ proc ssm to estimate a state space model. The following is the first part of that used:

proc ssm data=yield1 optimizer(technique=dbldog maxiter=600);
id date interval=month;
/*Observation equation white noise -- separate variance for each maturity */
parms lambda/ lower=1.e-4;
parms sigma1-sigma18 / lower=1.e-4;
array s_array(18) sigma1-sigma18;
do i=1 to 18;
if (type1=i) then sigma = s_array[i]; 
end;
irregular wn variance=sigma;
parms tsigma1-tsigma3/ lower=1.e-4; 
/* Variables Z1, Z2, Z3 needed in the observation equation */
Z1= 1.0;
tmp = lambda*m;
Z2 = (1-exp(-tmp))/tmp;
Z3 = ( 1-exp(-tmp)-tmp*exp(-tmp) )/tmp;
/* Zero-mean VAR(1) factor gamma and the associated component */
state gamma(3) type=VARMA(p(d)=1) cov(g) print=(cov ar);
comp gammaComp = (Z1-Z3)*gamma;
/* Constant mean vector mu and the associated component */
state mu(3) type=rw;
comp muComp = (Z1-Z3)*mu;
/* Observation equation */
model y= muComp gammaComp wn;
/* Various components defined only for the output purposes */
eval yieldSurface = muComp + gammaComp;
comp gamma1 = gamma[1];
comp gamma2 = gamma[2];
comp gamma3 = gamma[3];
comp mu1 = mu[1];
comp mu2 = mu[2];
comp mu3 = mu[3];
comp z2Gamma = (Z2)*gamma[2];
comp z3Gamma = (Z3)*gamma[3];
comp z2Mu = (Z2)*mu[2];
comp z3Mu = (Z3)*mu[3];
eval beta1 = mu1 + gamma1;
eval beta2 = mu2 + gamma2;
eval beta3 = mu3 + gamma3;

eval shortTem = z2Gamma + z2Mu;
eval medTerm = z3Gamma + z3Mu;
/* output the component estimates and the forecasts */
output out=dnsFor pdv;
run;

ID statement specified the year as ID variable but  month as interval variable in option.  Which  observations did proc ssm use in estimation?  all the observations or only the monthly data?  How did ID statement work?  

2 REPLIES 2
Steve1964
Obsidian | Level 7

Correction:

The first two lines of proc ssm should be

proc ssm data=yield optimizer(technique=dbldog maxiter=600);
id year interval=month;
Steve1964
Obsidian | Level 7

ID statement with invterval=option are often used in many SAS/ETS procedures and the variable in ID statement is the same as that in interval= option in most cases, which makes me wonder what's the function of  ID statement and ID variable. 

  I give an example here to illustrate the question.

First generate data set yield containing date and the returns of five different terns

data yield;
input date yymmdd10. r1 r2 r3;
format date yymmdd10.;
datalines;
2006/1/6 1.46294753 1.545676434 1.9558192 2.162519237 2.194832429
2006/1/13 1.517894442 1.549327787 1.669094293 1.988184834 2.221032995
2006/1/20 1.443779686 1.510635118 1.723018 1.943191704 2.204235341
2006/2/10 1.435783602 1.688414215 1.69724586 2.151445183 2.201574693
2006/2/17 1.6281019 1.817423293 1.680777269 2.163502995 2.260976889
2006/2/24 1.829734545 1.777889515 1.775476292 2.231772981 2.452023801
2006/3/3 1.75221336 1.845058223 1.806409006 2.133990918 2.241448065
2006/3/10 1.313178054 1.487231308 1.843614505 2.162158776 2.202237333
2006/3/17 1.627393859 1.714023033 1.975522236 2.218210508 2.187701008
2006/3/24 1.619900094 1.728668273 2.214861743 2.357222001 2.3055817
2006/3/31 1.691377603 1.850381878 2.132324347 2.341794321 2.593702564
2006/4/7 1.231735136 1.807453577 2.164653658 2.410393618 2.388405978
2006/4/14 1.449047203 1.713296575 2.294770498 2.474280203 2.667311041
2006/4/21 1.480894013 1.629524198 2.285539957 2.533601373 2.524863995
2006/4/28 1.141625772 1.789791092 2.161464221 2.340933419 2.457365711
2006/5/12 1.307451441 1.81715313 2.038693946 2.267437591 2.394994933
2006/5/19 1.439636654 2.080794775 2.108766763 2.313459556 2.4577652
2006/5/26 1.674160206 1.765928425 2.25844977 2.528455213 2.693901836
2006/6/2 1.482448956 2.21148808 2.349679345 2.507319142 2.804667556
2006/6/9 1.752021548 2.28769497 2.728398265 2.783386524 2.89890221
2006/6/16 2.209143133 2.209143133 2.290172298 2.549907972 2.827645284
2006/6/23 2.192305499 2.192305499 2.538649928 2.817736518 2.893188672
2006/6/30 1.357508534 2.232876297 2.459028163 2.486074859 2.729804656
2006/7/7 1.378897552 2.119779823 2.491028121 2.548943541 2.750352417
2006/7/14 1.284483937 2.210362629 2.674652884 2.714931149 2.762746862
2006/7/21 1.904280164 1.972541129 2.582892905 2.544756038 2.729714013
2006/7/28 1.826223252 1.985150783 2.562360161 2.591627008 2.757583994
;

Then employ proc ssm to estimate a state space model 

 

proc ssm data=yield1 optimizer(technique=dbldog maxiter=600);
id date interval=month;
/*Observation equation white noise -- separate variance for each maturity */
parms lambda/ lower=1.e-4;
parms sigma1-sigma18 / lower=1.e-4;
array s_array(18) sigma1-sigma18;
do i=1 to 18;
if (type1=i) then sigma = s_array[i];
end;
irregular wn variance=sigma;
parms tsigma1-tsigma3/ lower=1.e-4;
/* Variables Z1, Z2, Z3 needed in the observation equation */
Z1= 1.0;
tmp = lambda*m;
Z2 = (1-exp(-tmp))/tmp;
Z3 = ( 1-exp(-tmp)-tmp*exp(-tmp) )/tmp;
/* Zero-mean VAR(1) factor gamma and the associated component */
state gamma(3) type=VARMA(p(d)=1) cov(g) print=(cov ar);
comp gammaComp = (Z1-Z3)*gamma;
/* Constant mean vector mu and the associated component */
state mu(3) type=rw;
comp muComp = (Z1-Z3)*mu;
/* Observation equation */
model y= muComp gammaComp wn;
/* Various components defined only for the output purposes */
eval yieldSurface = muComp + gammaComp;
comp gamma1 = gamma[1];
comp gamma2 = gamma[2];
comp gamma3 = gamma[3];
comp mu1 = mu[1];
comp mu2 = mu[2];
comp mu3 = mu[3];
comp z2Gamma = (Z2)*gamma[2];
comp z3Gamma = (Z3)*gamma[3];
comp z2Mu = (Z2)*mu[2];
comp z3Mu = (Z3)*mu[3];
eval beta1 = mu1 + gamma1;
eval beta2 = mu2 + gamma2;
eval beta3 = mu3 + gamma3;

eval shortTem = z2Gamma + z2Mu;
eval medTerm = z3Gamma + z3Mu;
/* output the component estimates and the forecasts */
output out=dnsFor pdv;
run;

ID statement specified the year as ID variable but  month as interval variable in option.  Which  observations did proc ssm use in estimation?  all the observations or only the monthly data?  How did ID statement work?  

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 525 views
  • 0 likes
  • 1 in conversation