LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (July 2003, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 8 Jul 2003 10:40:52 -0400
Reply-To:   Bob Burnham <robert.a.burnham@DARTMOUTH.EDU>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Bob Burnham <robert.a.burnham@DARTMOUTH.EDU>
Organization:   Dartmouth College, Hanover, NH, USA
Subject:   Re: trim
Content-Type:   text/plain; charset=us-ascii

jieguo01@yahoo.com (ougya) writes:

+---------------------------------------------------------------- | I used the following code try to generate a string, which has | length of 2. THe ideal results would be a new variable | 'newstring', which combine char1 and char2 (both are character | and have length 1), however, using trim function gives me only | character of char1. Any wrong with my code? +----------------------------------------------------------------

The COMPRESS() function will bring you happiness and joy:

data test(drop=i); length newstring $2; array strings(2) $ char1 char2; do i = 1 to 2; if (strings(i)=' ') then strings(i)='M'; newstring = compress(newstring) || strings(i); end; run;

proc print noobs; run;

Gives you:

newstring char1 char2

MM M M

But why do concatenation? You know exactly where you want to put the character so just pop it in there with SUBSTR():

data test(drop=i); length newstring $2; array strings(2) $ char1 char2; do i = 1 to 2; if (strings(i)=' ') then strings(i)='M'; substr(newstring, i, 1) = strings(i); end; run;

-- Bob Burnham bburnham@dartmouth.edu http://www.dartmouth.edu/~bburnham


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