Understanding the SAS/IML Language


Matrix Literals

A matrix literal is an enumeration of the values of a matrix. For example, {1,2,3} is a numeric matrix with three elements. A matrix literal can have a single element (a scalar), or it can be an array of many elements. The matrix can be numeric or character. The dimensions of the matrix are automatically determined by the way you punctuate the values.

Use curly braces ({ }) to enclose the values of a matrix. Within the braces, values must be either all numeric or all character. Use commas to separate the rows. If you specify multiple rows, all rows must have the same number of elements.

You can specify any of the following types of elements:

  • a number. You can specify numbers with or without decimal points, and in standard or scientific notation. For example, 5, 3.14, or 1E-5.

  • a period (.), which represents a missing numeric value.

  • a number in brackets ([ ]), which represents a repetition factor.

  • a character string. Character strings can be enclosed in single quotes (') or double quotes ("), but they do not need to have quotes. Quotes are required when there are no enclosing braces or when you want to preserve case, special characters, or blanks in the string. Special characters include the following: ?, =, *, :, (, ), {, and }.

    If the string has embedded quotes, you must double them, as shown in the following statements:

    w1 = "I said, ""Don't fall!""";
    w2 = 'I said, "Don''t fall!"';