LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 2004, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 7 Apr 2004 14:47:58 -0400
Reply-To:   Venky Chakravarthy <venky.chakravarthy@PFIZER.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Venky Chakravarthy <venky.chakravarthy@PFIZER.COM>
Subject:   Re: Adding character to string
Comments:   To: "Roger Lustig (Citi)" <roger.lustig@CITIGROUP.COM>

Hi Roger,

I am aware of both issues. In a tangential way this provides continuity to the thread that Paul Choate started recently ( Re: Null Characters - was DO Loop Behavior with Increment of Zero). If you hadn't followed that, see in particular

http://listserv.uga.edu/cgi-bin/wa?A2=ind0404a&L=sas-l&F=&S=&P=8470

I find this as further confirmation of the data step developer's dislike for null strings.

Regards,

Venky

On Wed, 7 Apr 2004 14:25:01 -0400, Lustig, Roger <roger.lustig@CITIGROUP.COM> wrote:

>Venky: >Right you are! SAS character strings always have a LENGTH of 1 or more, even when blank. > >Not so for macro variables, by the way. %length(&some_variable) can return a 0. > >Roger > >-----Original Message----- >From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]On Behalf Of >Venky Chakravarthy >Sent: Wednesday, April 07, 2004 2:15 PM >To: SAS-L@LISTSERV.UGA.EDU >Subject: Re: Adding character to string > > >I prefer Roger's approach because it is the simplest. Predefining the >string to be 10 characters long ensures that the string will run out of >space in accommodating zeroes beyond the 10th character. However, I have >noticed one quirk with this approach. It needs a COMPRESS to make it work >when there is a null value. Somehow merely TRIMming the value fiercely >protects the first field and only appends 9 zeroes for the null value. >Uncomment and comment out the other instring manipulation alternatively to >see what I mean and count the number of zeroes for obs #4 in both. > >data q ; > length instring $10 ; > input instring $ ; > *instring = compress(trim(instring))||"00000000000" ; > instring = trim(instring)||"00000000000" ; > put "Obs #" _n_ INSTRING= ; > cards ; >0123456789 >12 >01234 >. >112 >9 >run ; > >Kind Regards, > >Venky > > >On Wed, 7 Apr 2004 11:01:48 -0400, Lustig, Roger ><roger.lustig@CITIGROUP.COM> wrote: > >>Nick: >>The LENGTH() function tells you where the last non-blank is. The TRIM() >function returns the string without its trailing blanks. Therefore: >> >>data new; >>length mystring $10; *<---- Put this here to modify a pre-existing >variable; >>set old; >>mystring=trim(mystring)||'0000000000'; >>run; >> >>Roger >> >>-----Original Message----- >>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]On Behalf Of Nick >>I >>Sent: Wednesday, April 07, 2004 10:55 AM >>To: SAS-L@LISTSERV.UGA.EDU >>Subject: Adding character to string >> >> >>Hello, >> >>I have a string 9 digits long like 000110100 but this field must be 10 >digits long. I would like to make it 10 digits long by adding a 0 at the >end like 000110100 >> >>How can I do this by first making sure the filed is 10 digits long, in >which case do nothing, but if it is short by 1 then add 0 at the end. (It >would be nice if program works for general case like for example: Say one >record is 4 digits long. Then I must add 6 0s at the end. So if it is like >0110 then it must look like 0110000000.) >>Thanks kindly >>Nick >>-- >>___________________________________________________________ >>Sign-up for Ads Free at Mail.com >>http://promo.mail.com/adsfreejump.htm


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