```Date: Wed, 13 Aug 2003 17:37:15 +0000 Reply-To: james grant Sender: "SAS(r) Discussion" From: james grant Subject: length of character string Content-Type: text/plain; format=flowed I'm getting different answers from problem 29 - 'How long is a piece of string?' from the book 'An Array of Challenges' by Robert Virgile. Perhaps it is simply a version 6 vs. 8.2 issue? Anyway, I'd like to confirm my understanding of the problem: data new ; string = repeat('X ', 50 ) ; L1 = length(string) ; L2 = length(repeat(string, 1)) ; L3 = length(compress(repeat('X ', 150))) ; L4 = length(string || string) ; string2 = repeat(string, 1) ; string3 = compress(repeat('X ', 150)) ; string4 = string || string ; put 'L1 ='L1 string ; put 'L2 ='L2 string2 ; put 'L3 ='L3 string3 ; put 'L4 ='L4 string4 ; run; The first half of the program is verbatim from the book. I added the second half . Consistent with the book, I get L1 = 101. However, I get 301 for L2. My interpretation is that the total length is 200 and the repeat adds another 101 for 301 total. Book says 101 - since it should only work with the first 200 characters. L3 = 151; book says 100. It would seem that all 252 characters are used, instead of the first 200. L4 = 301 ( 151+151 - 1 blank character?) Book says 255. Comments? Thanks, JG Here is my log (8.2 on Windows NT) 233 data new ; 234 string = repeat('X ', 50 ) ; 235 L1 = length(string) ; 236 L2 = length(repeat(string, 1)) ; 237 L3 = length(compress(repeat('X ', 150))) ; 238 L4 = length(string || string) ; 239 240 string2 = repeat(string, 1) ; 241 string3 = compress(repeat('X ', 150)) ; 242 string4 = string || string ; 243 put 'L1 ='L1 string ; 244 put 'L2 ='L2 string2 ; 245 put 'L3 ='L3 string3 ; 246 put 'L4 ='L4 string4 ; 247 run; INFO: Character variables have defaulted to a length of 200 at the places given by: (Line):(Column). Truncation may result. 234:5 string 240:5 string2 241:5 string3 L1 =101 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X L2 =301 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X L3 =151 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX L4 =301 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X NOTE: The data set WORK.NEW has 1 observations and 8 variables. NOTE: DATA statement used: real time 0.00 seconds cpu time 0.00 seconds _________________________________________________________________ MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus ```

Back to: Top of message | Previous page | Main SAS-L page