Language Reference |
reshapes and repeats character values
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.
For example, the following statement produces the matrix , as shown:
r=cshape('abcd',2,2,1);
R 2 rows 2 cols (character, size 1) a b c dThe following statement produces a different matrix , as shown:
r=cshape('a',1,2,3);
R 1 row 2 cols (character, size 3) aaa aaaThe following statement produces the matrix , as shown:
r=cshape({'ab' 'cd', 'ef' 'gh', 'ij' 'kl'}, 2, 2, 3);
R 2 rows 2 cols (character, size 3) abc def ghi jklThe following statement produces the matrix , as shown:
r=cshape('XO',3,3,1);
R 3 rows 3 cols (character, size 1) X O X O X O X O XFinally, the following statement produces the matrix , as shown:
r=cshape('abcd',2,2,3,'*');
R 2 rows 2 cols (character, size 3) abc d** *** ***
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.