IMSTAT Procedure (Analytics)

Example 14: Aggregating Time Series Data

Details

This IMSTAT procedure example demonstrates using AGGREGATE statement with time series data.

Program

libname example sasiola host="grid001.example.com" port=10010 tag='hps';

data example.stocks; 
    set sashelp.stocks; 
run;

proc imstat data=example.stocks;
    where stock="IBM";
    aggregate close (agg=min) close (agg=max) close (agg=mean)  1
              / id=date idstart='01jan1998'd idend='31dec1998'd   2
                interval="quarter";  3
run;

    where same and date >= '01jan2003'd;  4

    aggregate close (agg=n) close (agg=mean) close (agg=stddev) 
              / id=date idfmt="yyq6." interval="quarter" temptable;  5

    table example.&_templast_;
    fetch / format;  6

quit;

Program Description

  1. The three aggregate expressions calculate the minimum, maximum, and mean values of the Close variable.
  2. The Date variable is used to identify the time associated with each observation. The IDSTART= and IDEND= options limit the series to a single year.
  3. The INTERVAL= option specifies to aggregate the observations by quarter.
  4. The WHERE SAME clause is used to add a clause to the existing WHERE statement. In this case, it is used to subset the time series.
  5. The second AGGREGATE statement calculates the count, mean, and standard deviation of the Close variable. The Date variable is formatted as YYQ6. and the observations are aggregated by quarter. The TEMPTABLE option saves the results of the aggregation to a temporary in-memory table.
  6. The TABLE statement sets the temporary table as the active table. The FETCH statement prints the formatted values of the table.

Output

The first table shows the results of the first AGGREGATE statement. The second table shows the name of the temporary in-memory table that has the results of the second AGGREGATE statement. The third table shows the contents of the temporary table. The Date_f column shows the formatted values of the Date column that were applied with the IDFMT= option. The other column headings include the name of the analysis variable, Close, and the aggregate method.
Aggregating time series data