There
are many ways to subset data in SAS by using the following tools:
-
a WHERE statement in a view descriptor
-
-
a PROC
SQL SELECT statement's WHERE clause
-
a WHERE command in the
SAS/FSP procedures
-
These all use SAS WHERE statement syntax. You do not have to use IMS SSA syntax with
the IMS engine that runs under SAS 7 and later.
The IMSI engine attempts to build SSAs from the WHERE conditions that you enter; condition refers to the expression(s) in the WHERE statement, clause, command, or option. The
engine uses these SSAs to qualify each call to the database. Therefore, IMS returns
to SAS only those observations that meet your conditions.
However, if the IMS engine cannot convert the WHERE condition into SSAs, it passes
all database segments referenced by the view descriptor to SAS, which then subsets
and processes the data. Because it uses more resources
to have SAS process WHERE conditions, you should try to use WHERE conditions that
can be turned into valid SSAs when resources are a concern.
To specify WHERE conditions that the IMS engine can use to generate SSAs, use one
of the operators supported by IMS. In the access descriptor, define
search field names from the
DBD for all the variables included in your WHERE condition when possible. See
Writing Efficient WHERE Statements for a list of the operators IMS
supports.
Note: IMS SSAs do not support conditions
that use OR and combine elements from two different segments.
The engine uses the search field names that are entered in the view descriptor for
the field names in the SSAs. Therefore, if you use a
SAS variable in a WHERE condition for which you have not defined a search field, the IMS engine
cannot generate SSAs for that WHERE condition.
If the WHERE statement or clause contains multiple conditions and any one of the conditions
cannot generate a qualified SSA, then no qualified SSA is generated from the statement
or clause.
If the IMS engine can handle a WHERE condition, it uses the SEARCH= argument in the
ITEM= statement
to generate a qualified SSA. If possible, the engine combines the qualified SSAs that
it generated to navigate
the database with any WHERE condition SSAs. If both SSAs involve the same field, only
the WHERE SSA is used to avoid a mutually exclusive situation. The engine then issues
a
path call to obtain the segments in the hierarchy down to the lowest level with an item specified
in the WHERE condition. All segments in the path are retrieved and passed to SAS.
Therefore, if you use a WHERE condition from which
the IMS engine can generate SSAs, the
Program Specification Block (
PSB) specified in that view descriptor must let the path calls for the segments in the
hierarchy above and including segments
with variables in the WHERE condition.
For example, if you
enter the WHERE condition
WHERE CHCKACCT = 345620145345
the IMS engine passes the following SSAs to IMS:
CUSTOMER*D-
CHCKACCT*--(ACNUMBERREQ345620145345)
The IMS engine uses the results of this call to generate SSAs to navigate the database
further and to flatten out the IMS record as defined in the view descriptor. The
engine combines these navigational SSAs with the SSA that it generated from the WHERE
condition for the CHCKACCT segment. The engine continues processing and retrieves
the view descriptor's lowest level
segment (CHCKDEBT), which is a child of the CHCKACCT segment. CHCKACCT has an ACNUMBER
value that is equal to 345620145345 until the engine does not find another CHCKDEBT
segment (
status code GE).
To improve the efficiency of using a WHERE condition to subset your data, use the
operators supported by IMS. Enter the search field names of all variables in the
WHERE condition so that the IMS engine can pass only a subset of data to SAS for further
processing. Use the SAS system
option IMSDEBUG=Y to see whether your WHERE condition is generating SSAs directly.
Note: For GSAM databases, the
IMS engine always passes WHERE clauses to SAS for processing.