Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Language Reference

CSHAPE Function

reshapes and repeats character values

CSHAPE( matrix, nrow, ncol, size<, padchar>)

The inputs to the CSHAPE function are as follows:
matrix
is a character matrix or quoted literal.

nrow
is the number of rows.

ncol
is the number of columns.

size
is the element length.

padchar
is a padding character.
The CSHAPE function shapes character matrices. See also the description of the SHAPE function, which is used with numeric data. The dimension of the matrix created by the CSHAPE function is specified by nrow (the number of rows), ncol (the number of columns), and size (the element length). A padding character is specified by padchar.

The CSHAPE function works by looking at the source matrix as if the characters of the source elements had been concatenated in row-major order. The source characters are then regrouped into elements of length size. These elements are assigned to the result matrix, once again in row-major order. If there are not enough characters for the result matrix, the source of the remaining characters depends on whether padding was specified with padchar. If no padding was specified, the source matrix's characters are cycled through again. If a padding character was specified, the remaining characters are all the padding character.

If one of the dimension arguments (nrow, ncol), or size) is zero, the function computes the dimension of the output matrix by dividing the number of elements of the input matrix by the product of the nonzero arguments.

Some examples follow. The statement

   r=cshape('abcd',2,2,1);
results in
        R        2 rows      2 cols    (character, size 1)

                             a b
                             c d
The statement
   r=cshape('a',1,2,3);
results in
           R        1 row       2 cols    (character, size 3)

                              aaa aaa
The statement
   r=cshape({'ab' 'cd',
             'ef' 'gh',
             'ij' 'kl'}, 2, 2, 3);
results in
           R         2 rows      2 cols    (character, size 3)

                              abc def
                              ghi jkl
The statement
   r=cshape('XO',3,3,1);
results in
           R          3 rows      3 cols    (character, size 1)

                                 X O X
                                 O X O
                                 X O X
And finally, the statement
   r=cshape('abcd',2,2,3,'*');
results in
           R           2 rows      2 cols    (character, size 3)

                                 abc d**
                                 *** ***

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.