1. Home
  2. SUBSET procedure

SUBSET procedure

Forms vectors containing subsets of the values in other vectors (R.W. Payne).

Options

CONDITION = expression Logical expression to define which units are to be included; no default – this option must be set
SETLEVELS = string token Whether to reform the levels (and labels) of factors to exclude those that do not occur in the subset (yes, no); default no
NULL = scalar Indicator set to 1 or 0 according to whether or not the subset contains no units

Parameters

OLDVECTOR = vectors Vector from which the subset is to be formed
NEWVECTOR = vectors Vector to store the subsets if none is specified, the OLDVECTOR is redefined to store the subset

Description

SUBSET forms vectors containing subsets of the values in other vectors. The subset is defined by a logical condition which must be specified by the CONDITION option; units with true values (non-zero and non-missing) for the condition are included in the subset, others are omitted.

Subsets can be formed for factors, texts and variates. Relevant attributes will also be transferred across to the new structures but, if the subset excludes some of the levels of a factor, a new reduced set of levels (and labels) can be requested by setting option SETLEVELS=yes.

The NULL option can specify a scalar that will be set to one if the subset contains no units; otherwise it is set to zero. Also, when NULL set, SUBSET suppresses the fault that it normally gives if the subset is empty.

The original vectors are specified by the OLDVECTOR parameter and identifiers for the vectors to contain the subsets are specified by the NEWVECTOR parameter. If NEWVECTOR is not set, the OLDVECTOR are redefined to store the subsets instead of their original values.

Options: CONDITION, SETLEVELS, NULL.

Parameters: OLDVECTOR, NEWVECTOR.

Method

RESTRICT is used to obtain a list of units included according to the CONDITION. This is then used to calculate a format for EQUATE to use to transfer the values. The DUPLICATE directive is used to transfer any relevant attributes. We thank Jac Thissen for suggestions about the redefinition of factor levels.

Action with RESTRICT

Any restriction is ignored; the subset is formed only from the CONDITION option.

OLDVECTOR is redefined to store the subset.

See also

Directive: EQUATE.

Procedure: UNSTACK.

Commands for: Calculations and manipulation.

Example

CAPTION 'SUBSET example',\ 
        'Form a subset of a variate.'; STYLE=meta,plain
VARIATE [VALUES=101...126] X
SUBSET  [CONDITION=X<111] OLDVECTOR=X; NEWVECTOR=Xs
PRINT   Xs
CAPTION 'Form a subset of a text.'
TEXT    [VALUES=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z] T
SUBSET  [CONDITION=X<111] OLDVECTOR=T; NEWVECTOR=Ts
PRINT   Ts
CAPTION 'Form a subset of a factor.'
FACTOR  [LEVELS=26; VALUES=1...26] F
SUBSET  [CONDITION=X<111] OLDVECTOR=F; NEWVECTOR=Fs
PRINT   Fs
Updated on March 5, 2019

Was this article helpful?