1. Home
  2. TX2VARIATE directive

TX2VARIATE directive

Converts text structures to variates.


PRINT = string token Controls printed output (conversions) ; default * (i.e. none)
NONNUMERIC = string token How to treat non-numeric values (bestmatch, missing) default miss
YEAR = scalar Year to use when calculating the day within year for the date formats that specify only months and days; default is to assume that this is any year that is not a leap year
REDEFINE = string token Whether to allow a structure in the VARIATE list that has already been declared (e.g. as a text) to be redefined (yes, no); default no


TEXT = texts Text structures to convert
VARIATE = variates Variate for each text, containing the numbers in each of its lines
DREPRESENTATION = scalars Format to use for dates and times (stored in numerical structures)
MISSING = texts Strings used to represent missing values in each text; default ‘*’
STATUS = variates Code to indicate whether the number in each unit was read successfully (1), or with conversions (2), or unsuccessfully (0)


The TX2VARIATE directive converts texts to variates. The texts are specified by the TEXT parameter, and are assumed to contain a single number in each of their strings. The variates are specified by the VARIATE parameter. The DREPRESENTATION parameter specifies the format that has been used for texts that contain dates. For details, see the PRINT directive. With the formats that specify only months and days, TX2VARIATE gives the number of the day within the year. However, it needs to know whether or not the year is a leap year. You can use the YEAR option to supply the year. If this is not set, TX2VARIATE assumes that it is not a leap year. The MISSING parameter specifies a text for each text and variate, containing the string or strings that should be treated as missing values in the conversion; by default this is the string containing a single asterisk. Blank and null lines are always treated as missing.

By default, any non-numeric strings generate a missing value in the variate. However, you can set option NONNUMERIC=bestmatch to ignore commas, and to allow for the common typing errors that the letters i or l may have been typed instead of i, or that the letters o or O may have been typed instead of 0. You can set option PRINT=conversions to print a list of the values that have been converted. Also, the STATUS parameter can save a variate with a code for each number to show whether it was read successfully with no conversions (1), or only with conversions (2), or whether it could not be read successfully (0).

If you set option REDEFINE=yes, any data structure specified by the VARIATE parameter that is not a variate will be redefined (to be a variate). Also, VARIATE then takes the setting of the TEXT parameter as its default, i.e. it will redefine that text to be a variate.


Action with RESTRICT

TX2VARIATE takes account of restrictions on each TEXT or VARIATE. The values of the VARIATE in the units excluded by the restriction are left unchanged.

See also

Directives: TEXT, READ.
Commands for: Calculations and manipulation.


" Example 1:4.5.3 "
TEXT       [VALUES=' 0.01',' -1','2.2','3.3E1',il,'-IO',O,'1,001',\
           ' ','*','notnumber!','3.3D2','1.23E-4','-1.23E'] Textvals
TX2VARIATE [PRINT=conversions; NONNUMERIC=bestmatch] Textvals;\
           VARIATE=Realvals; Status=Status
PRINT      Textvals,Realvals,Status; DECIMALS=*,6,0
TEXT       [VALUES='1/12/01','27/1/02','1/1/03','28/7/04','16/11/08',\
            '4/7/14','11/5/15','21/10/16','12/3/17','3/4/17'] Tdate
PRINT      Tdate,Vdate,Vdate; DREPRESENTATION=0,0,3
Updated on October 28, 2020

Was this article helpful?