A temporary table is
an in-memory table that contains the result set of a procedure statement.
Instead of transferring the results to the client SAS session, the
results remain in the server and only the name of the temporary table
is transferred to the client. You can then use other procedure statements
with the temporary table.
Temporary tables can
be partitioned and the SUMMARY, CROSSTAB, DISTINCT, and PERCENTILE
statements perform this action. For non-partitioned data, you can
also generate temporary tables with the SUMMARY and CROSSTAB statements,
provided that you request a GROUPBY analysis.
The following DATA
step shows how to create a partitioned table on the variables Country
and Region.
data lasr.prdsale(partition=(country region));
set sashelp.prdsale;
run;
The following statements
generate a summary analysis for variables Actual and Predict in each
of the partitions.
proc imstat;
table lasr.prdsale;
summary actual predict / partition;
run;
The output for the
previous statements is as follows:
As an alternative,
you can leave the result set in an in-memory table by adding the TEMPTABLE
option to the SUMMARY statement:
summary actual predict / partition temptable;
run;
The previous SAS statements
generate the following output in the SAS session.
The temporary table
is assigned a name by the server. When the IMSTAT procedure ends,
any temporary tables created during the procedure run are removed
from the server. Since the generated name is not predictable, the
procedure assigns the name of the most recently generated temporary
table to the _TEMPLAST_ macro variable.
You can use the TABLE
statement to switch the active table to the temporary table and perform
analyses. Make sure that the statement that generated the temporary
table is separated from the next statement with a RUN statement. Otherwise,
you receive an error that the table specified in the TABLE statement
does not exist. The temporary table does not exist at parse time,
it is created at run time when the statement is executed.
The following statements
retrieve information about the temporary table, the formatted values
for (up to) the first twenty rows, and perform a summarization:
table lasr.&_templast_
tableinfo;
columninfo;
fetch / from=1 to=20 format;
summary;
quit;
The output for the
TABLEINFO, COLUMNINFO, and FETCH statements is not shown. The results
for the SUMMARY statement are as follows: