SED navigation bar go to SED home page go to Dataplot home page go to NIST home page SED Home Page SED Staff SED Projects SED Products and Publications Search SED Pages
Dataplot Vol 1 Vol 2

CHARACTER CODE

Name:
    CHARACTER CODE (LET)
Type:
    Subcommand under LET
Purpose:
    Converts previously read character data to a coded numeric variable.
Description:
    Dataplot can read character data using the

    command. This command stores the character fields in the file "dpchzf.dat".

    The two primary uses of character data are:

    1. Provide a row identifier for the data.

    2. Define a group (or factor) variable. For example, we can identify sex by coding males as M and females as F.

    In the context of Dataplot, we can use groups in two contexts.

    1. The group variable can be used in a numerical context. For example,

        BOX PLOT Y X

      Here, X is the group-id variable.

      The command CHARACTER CODE (or ALPHABETIC CHARACTER CODE or REFERENCE CHARACTER CODE) can be used to create a coded numeric variable from a character variable saved in the file dpchzf.dat.

    2. We can use the group label for labeling. In this case, we typically want to use the character coding.

      The GROUP LABEL command is used to create character group labels from a character variable saved in the file dpchzf.dat.

      The GROUP LABEL will extract and save the unique rows for the specified character variable.

    The CHARACTER CODE command identifies the unique rows in the character variable (Dataplot checks for exact matches, it does not try to guess if a typo has occurred, etc.). If there are K unique rows, Dataplot will generate coded values as the integer values from 1 to K. The CHARACTER CODE performs the coding in the order that the unique rows are encoutered in the file.

    The ALPHABETIC CHARACTER CODE is a variant of the CHARACTER CODE command that sorts the unique character rows and assigns the code based on the alphabetic order of the character rows.

    There may be some cases where we want to control the mapping from the character variable to the coded numeric variable. The REFERENCE CHARACTER CODE can be used in this case. We define a group label variable that defines the desired ordering. The numeric coding is then based on the ordering given with the group label variable. This is demonstrated in the Program 2 example below.

Syntax 1:
    LET <y> = CHARACTER CODE <ix>
    where <ix> specifies the name of the character variable in the file dpzchf.dat;
    and    <y> specifies the name for the coded numberic variable to be saved.

    The character variable is originally created with a READ command where the SET CONVERT CHARACTER ON was entered prior to the READ.

Syntax 2:
    LET <y> = ALPHABETIC CHARACTER CODE <ix>
    where <ix> specifies the name of the character variable in the file dpzchf.dat;
    and    <y> specifies the name for the coded numberic variable to be saved.

    The character variable is originally created with a READ command where the SET CONVERT CHARACTER ON was entered prior to the READ.

    This syntax assigns the codes based on the alphabetic order of the character variable.

Syntax 3:
    LET <y> = REFERENCE CHARACTER CODE <ix> <ig>
    where <ix> specifies the name of the character variable in the file dpzchf.dat;
                <ig> specifies the name of a previously created group label variable; and    <y> specifies the name for the coded numberic variable to be saved.

    The character variable is originally created with a READ command where the SET CONVERT CHARACTER ON was entered prior to the READ.

    This syntax assigns the codes based on the ordering in the group label variable.

Examples:
    SET CONVERT CHARACTER ON
    READ TEST.DAT Y X IX
    LET Y = CHARACTER CODE IX
Default:
    None
Synonyms:
    None
Related Commands:
    READ = Carries out a column-wise input of data.
    CONVERT CHARACTER = Specify how Dataplot will handle character data.
    GROUP LABEL = Converts character data to a group label variable.
    ROWLABEL = Define row labels from character data.
Applications:
    Input/Output
Implementation Date:
    2004/01
    2018/06: Support for the REFERENCE CHARACTER CODE case
Program 1:
     
    set convert character on
    skip 25
    read draft69c.dat rank day month
    .
    let ig = group label month
    x1tic mark label format group label
    x1tic mark label content ig
    x1tic mark label font simplex
    x1tic mark label angle 45
    x1tic mark label displacement 10
    let xcode = character code month
    .
    major xtic mark number 12
    minor xtic mark number 0
    xlimits 1 12
    xtic offset 0.5 0.5
    .
    char box plot
    line box plot
    fences on
    .
    box plot rank xcode
        
    plot generated by sample program
Program 2:
     
    skip 1
    set convert character on
    read refcode.dat comp method lab ymean ysd ni
    set convert character off
    skip 0
    .
    . Step 2: Create coded values
    .
    let string l1 = NIST
    let string l2 = CTL
    let il = group label l1 l2
    .
    let string m1 = XRF
    let string m2 = TGA
    let string m3 = ISE
    let string m4 = GRAV
    let string m5 = ICP
    let im = group label m1 to m5
    .
    let string c1 = ZnO
    let string c2 = Cl
    let string c3 = LOI220
    let string c4 = LOI550
    let string c5 = LOI950
    let string c6 = Na2O
    let string c7 = MgO 
    let string c8 = Al2O3
    let string c9 = K2O
    let string c10 = TiO2
    let string c11 = Cr2O3
    let string c12 = Mn2O3
    let string c13 = Fe2O3
    let string c14 = SO3
    let string c15 = SiO2
    let string c16 = P2O5
    let string c17 = CaO
    let string c18 = SrO
    let string c19 = BaO
    let ic = group label c1 to c19
    .
    let ycomp = reference character code comp   ic
    let ymeth = reference character code method im
    let ylab  = reference character code lab    il
    status f
    print il im ic
    .
    set write decimals 0
    print ycomp ymeth ylab
        
    The following output is returned
     
    ---------------------------------------------
              YCOMP          YMETH           YLAB
    ---------------------------------------------
                  1              1              1
                  1              1              2
                  2              1              1
                  2              3              2
                  5              2              1
                  5              2              2
                  4              2              1
                  4              2              2
                  3              2              1
                  3              2              2
                  6              1              1
                  6              1              2
                  6              5              2
                  7              1              1
                  7              1              2
                  7              5              2
                  8              1              1
                  8              1              2
                  8              5              2
                  9              1              1
                  9              1              2
                  9              5              2
                 10              1              1
                 10              1              2
                 10              5              2
                 11              1              1
                 11              1              2
                 11              5              2
                 12              1              1
                 12              1              2
                 12              5              2
                 13              1              1
                 13              1              2
                 13              5              2
                 14              1              1
                 14              1              2
                 14              5              2
                 14              4              2
                 15              1              1
                 15              1              2
                 15              4              2
                 16              1              1
                 16              1              2
                 16              4              2
                 17              1              1
                 17              1              2
                 17              5              2
                 17              4              2
                 18              1              1
                 18              1              2
                 18              5              2
                 19              1              1
                 19              1              2
                 19              5              2
        

Privacy Policy/Security Notice
Disclaimer | FOIA

NIST is an agency of the U.S. Commerce Department.

Date created: 02/03/2004
Last updated: 11/07/2018

Please email comments on this WWW page to alan.heckert@nist.gov.