/*--------------------------------------------------------------

                    SAS Sample Library

        Name: hpfex02.sas
 Description: Example program from SAS Forecast Server
              Procedures User's Guide,
              The HPF Procedure
       Title: Automatic Forecasting of Transactional Data
     Product: SAS Forecast Server Procedures Software
        Keys: time series forecast
        PROC: HPF
       Notes:

--------------------------------------------------------------*/

data websites (label="Transactional Internet data");

/*- time variable definition -*/
    keep time;
    format time datetime.;
    label time="Time of Web Hit";
    starttime = '12mar2000:00:00:00'dt; /*- Sunday -*/
    seedtime = 1234321;

/*- cars variable definition -*/
    keep cars;
    format cars best12.;
    label cars="Number of Car Webhits";
    seedcar = 321123;

/*- boats variable definition -*/
    keep boats;
    format boats best12.;
    label boats="Number of Boat Webhits";
    seedboat = 987789;

/*- planes variable definition -*/
    keep planes;
    format planes best12.;
    label planes="Number of Planes Webhits";
    seedplane = 567765;

/*- engines variable definition -*/
    keep engines;
    format engines best12.;
    label engines="Number of Engine Webhits";
    seedengine = 345543;

/*- simulate the data -*/
    do day = 1 to 30;
       season = abs(4 - mod(day,7));
       nhits = ceil(10*ranuni(seedtime));
       intv = 24*3600*ranuni(seedtime)/nhits;
       do hits = 1 to nhits;

       /*- randomly generate the next time -*/
           intv = intv + 24*3600*ranuni(seedtime)/nhits;
           intv = int(intv);
           time = intnx( 'DTDAY', starttime, day );
           time = intnx( 'DTSECOND', time, intv );

       /*- randomly generate car data -*/
            cars = 1000 + 600*day + 1000*season
                 + 10*rannor(seedcar);
            cars = int(cars);

       /*- randomly generate boats data -*/
           boats = 1000 + 1000*season +
                 + 10*rannor(seedboat);
           boats = int(boats);

       /*- randomly generate planes data -*/
           planes = 1000 - 10*day +
                  + 10*rannor(seedplane);
           planes = int(planes);

       /*- randomly generate engines data -*/
           engines = 1000 + 1*cars - 2*boats + 4*planes
                   + 10*rannor(seedengine);
           engines = int(engines);

           output;
       end;
    end;

run;

proc sort data=websites; by time; run;

proc hpf data=websites out=nextweek lead=7;
   id time interval=dtday accumulate=total;
   forecast boats cars planes;
run;

title1 "Website Data";
proc sgplot data=nextweek noautolegend;
   series x=time y=boats / markers
      markerattrs=(symbol=circlefilled) lineattrs=(pattern=1);
   series x=time y=cars / markers
      markerattrs=(symbol=circlefilled) lineattrs=(pattern=1);
   series x=time y=planes / markers
      markerattrs=(symbol=circlefilled) lineattrs=(pattern=1);
   xaxis values=('13MAR2000:00:00:00'dt to '18APR2000:00:00:00'dt by dtweek);
   yaxis label='Websites';
   refline '11APR2000:00:00:00'dt / axis=x;
run;