1. Home
  2. FACGETLABELS procedure

FACGETLABELS procedure

Obtains the labels for a factor if it has been defined with labels, or constructs labels from its levels otherwise (V.M. Cave).

Options

PRINT = string token Controls printed output (labels); default *
PREFIX = text Supplies a single line of text to be used as a prefix when constructing labels from the factor levels; default * i.e. none

Parameters

FACTOR = factors Factor whose labels are to be obtained
LABELS =texts Specifies text structures to save the labels of each factor
EXIST = scalars Specifies a scalar for each factor, set to the value 1 if its labels already existed or 0 if they had to be constructed

Description

FACGETLABELS can be used to obtain the labels of a factor. If the factor has been defined without any labels, they are constructed from its levels.

The factor whose labels are to obtained (or constructed) is specified using the FACTOR parameter. The LABELS parameter can be used to save the labels in a text structure. The EXIST parameter can save a scalar that indicates whether the labels already existed (= 1), or had to be constructed (= 0).

The PRINT option can be set to labels to print the resulting labels; by default, nothing is printed. The PREFIX option can supply a text containing a single string, to be used as a prefix when constructing labels from factor levels. The string is inserted before the level numbers to form the labels. For factors with defined labels, PREFIX is ignored.

Options: PRINT, PREFIX.

Parameters: FACTOR, LABELS, EXIST.

Method

FACGETLABELS uses GETATTRIBUTE to get the necessary attributes. If there are no labels, TXCONSTRUCT is used to form them from the levels and any prefix.

Action with RESTRICT

Any restrictions on the factors supplied by FACTOR are ignored.

See also

Directive: GETATTRIBUTE, TXCONSTRUCT.

Example

CAPTION 'FACGETLABELS example'; STYLE=meta

"Factor with labels defined"
FACTOR [LEVELS=2; LABELS=!T(male,female)] Sex; VALUES=!T(4(male,female))
FACGETLABELS [PRINT=labels] Sex; LABELS=LabelsSex

"Factor without labels defined"
FACTOR [LEVELS=!(2,4,8,16); VALUES=8,4,2,16,4,2,16,8,2] Dose
FACGETLABELS [PRINT=labels] Dose; LABELS=LabelsDose
"Add preceding text when creating factor labels from levels"
FACGETLABELS [PRINT=labels; PREFIX='Rate '] Dose; LABELS=LabelsDose
Updated on June 19, 2019

Was this article helpful?