TSMODEL Procedure
Example 29.3 Using Auxiliary Tables
This example demonstrates the use of the AUXDATA= option in the PROC TSMODEL statement. The data set Sashelp.Gulfoil contains oil and gas production data from the Gulf of Mexico. The following DATA step loads data set Sashelp.Gulfoil into the table mylib.gulfoil.
These statements assume that your libref is named mylib, but you can substitute any appropriately defined libref.
data mylib.gulfoil(replace=yes);
set sashelp.gulfoil;
run;
The variable RegionName define a time series hierarchy of interest. Suppose you want to generate two new series that contain the region’s total share of oil and gas production for each month in the mylib.gulfoil table.
You first use PROC TSMODEL to perform temporal aggregation (accumulation) of the time series:
proc tsmodel data=mylib.gulfoil
outarray=mylib.allreg(replace=yes);
id date interval=month accumulate=total;
var oil gas;
outarray alloil allgas;
submit;
do t=1 to _length_;
alloil[t]=oil[t];
allgas[t]=gas[t];
end;
endsubmit;
quit;
In the preceding PROC TSMODEL statements, the Oil and Gas variables are accumulated across all regions because no BY statement is specified. In the following DATA step, the variables are dropped from the mylib.allreg table to avoid conflict with the original time series variables in the mylib.gulfoil table:
data mylib.allreg;
set mylib.allreg;
drop oil gas;
run;
You can then use PROC TSMODEL with the AUXDATA= option to compute the share of oil and gas production that is contributed by each region for each month. PROC TSMODEL reads a monthly time series for each RegionName group for the variables Oil and Gas from mylib.Gulfoil. Two new series are produced in the variables Oilshare and Gasshare, which contain the region’s share of the oil and gas production, respectively. Those share variables are specified in the OUTARRAY statement for inclusion in the table (mylib.shares), which is specified in the OUTARRAY= option. The time series that are acquired for the variables alloil and allgas are common across all of the RegionName BY groups.
proc tsmodel data=mylib.gulfoil
auxdata=mylib.allreg
outarray=mylib.shares;
by regionname;
outarray oilshare gasshare;
var oil gas alloil allgas;
id date interval=month accumulate=total;
submit;
do i=1 to _length_;
oilshare[i] = oil[i] / alloil[i];
gasshare[i] = gas[i] / allgas[i];
end;
endsubmit;
quit;
The following code demonstrates that the computed shares sum to 1 for each time index in the resulting Oilshare and Gasshare series. PROC TSMODEL is used to accumulate the shares for these respective variables from the table mylib.shares, and the accumulated share series at the RegionName level are stored to the table mylib.rshares with variable names Oilsum and Gassum, respectively. The tables mylib.shares and mylib.rshares are shown in Output 29.3.1.
proc tsmodel data=mylib.shares
outscalar=mylib.rshares(replace=yes)
outsum=mylib.rsum(replace=yes);
id date interval=month accumulate=total;
var oilshare gasshare;
outscalar oilsum gassum;
submit;
oilsum = 0;
gassum = 0;
do t=1 to _length_;
oilsum = oilsum + oilshare[t];
gassum = gassum + gasshare[t];
end;
endsubmit;
quit;
proc print data=mylib.rshares; run;
proc print data=mylib.rsum; run;
Output 29.3.1: Validation of Oil and Gas Shares by Region
| Obs | _STATUS_ | oilsum | gassum |
|---|---|---|---|
| 1 | 0 | 123 | 123 |
| Obs | _NAME_ | NOBS | N | NMISS | MIN | MAX | MEAN | STDDEV | SUM | _STATUS_ | START | END | STARTOBS | ENDOBS |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | oilshare | 123 | 123 | 0 | 1 | 1 | 1 | 0 | 123 | 0 | JAN1996 | MAR2006 | 1 | 123 |
| 2 | gasshare | 123 | 123 | 0 | 1 | 1 | 1 | 0 | 123 | 0 | JAN1996 | MAR2006 | 1 | 123 |
You might also want to plot the share series. The following code produces a graph that overlays the region level share series for oil production as shown in Output 29.3.2.
proc sgplot data=mylib.shares;
series x=Date y=OilShare/group=RegionName;
run;
Output 29.3.2: Region Share of Oil Production
