This is a pretty cool feature, and as far as I know it's unique to SAS and Perl. In SAS, you can have a substr to the left of an assignment.
This avoids potentially awkward situations like this:
The bounds don't have to be static. Lets suppose we have a dataset with 1 row per letter, and we want to combine those letters into a word.
data have; input letter $1.; datalines; h e l l o ; run;
My initial thought was to just retain and append each letter:
data want; length word $200; retain word; set have nobs=nobs; call cats(word,letter); if(nobs=_n_) then output; run;
However this breaks if one of the letters is a space, and SAS treats the space as null, so appending a space has no effect on the string. Instead of appending, just stick the letter where it's supposed to be.
data want; length word $200; retain word ' '; set have nobs=nobs; substr(word,_n_,1) = letter; if(_n_==nobs) then output; run;