d*******1 发帖数: 293 | 1 data work. test;
First = 'Ipswich, England';
City_Country = substr(First, 1, 7)!!', '! !'England';
run;
Which one of the following is the length of the variable CITY_COUNTRY in the
output data set?
A. 6
B. 7
C. 17
D. 25
Answer: D
But when I run the program in SAS, it is 16. How here get 25, just because
substr do not change length of First? but why I got 16 from SAS? | P****D 发帖数: 11146 | 2 The answer is indeed 25. Take a look at the attribute of variable "City_Country" and you will find the length is 25. The length of substr(First, 1, 7) is still 16, as First has a length of 16. | d*******1 发帖数: 293 | 3 Yes, I got 25 from attribute.
But why when I used Length(City_Country) in SAS program and got 16? | P****D 发帖数: 11146 | 4 According to SAS Help and Documentation -
LENGTH Function
finds the lengths of character matrix elements
LENGTH( matrix)
where matrix is a character matrix or quoted literal.
The LENGTH function takes a character matrix as an argument and produces a
numeric matrix as a result. The result matrix has the same dimensions as the
argument and contains the lengths of the corresponding string elements in
matrix. The length of a string is equal to the position of the rightmost
nonblank character in the | d*******1 发帖数: 293 | |
|