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 (July 2003, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 22 Jul 2003 16:52:54 -0600
Reply-To:     Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Subject:      Re: Conditional character concatenation
Comments: To: MurffMJ@LDSCHURCH.ORG
Content-Type: text/plain; charset=us-ascii

As Ravi has pointed out, the obvious approach would be to use a w.d format, where D=3, but I assume you've rejected that approach.

Here's an all string method, not very refined:

===== 103 data _null_; 104 105 set test; 106 107 if 0 then 108 do; 109 firstpart = stuff; 110 secondpart = stuff; 111 end; 112 113 length newsecondpart $3; 114 115 firstpart = scan(stuff, 1, '.'); 116 secondpart = scan(stuff, 2, '.'); 117 118 newsecondpart = trim(secondpart) || '000'; 119 120 newstuff = trim(firstpart) || '.' || newsecondpart; 121 122 put stuff= newstuff=; 123 124 *****; run;

stuff=3.5 newstuff=3.500 stuff=3.51 newstuff=3.510 stuff=3.511 newstuff=3.511 stuff=12.1 newstuff=12.100 stuff=12.11 newstuff=12.110 stuff=12.111 newstuff=12.111 =====

-- JackHamilton@FirstHealth.com Manager, Technical Development Metrics Department, First Health West Sacramento, California USA

>>> "Michael Murff" <MurffMJ@LDSCHURCH.ORG> 07/22/2003 3:37 PM >>> Dear SAS-L,

I want to conditionally concatenate zeros onto the end of a string. The condition is how many characters exist to the _right_ of the decimal. I need all values to have zeros out to three decimal places IF no other integer occupies that space; else the variable should remain unchanged. For instance,

3.5 --> 3.500 3.51 --> 3.510 3.511--> 3.511 12.1-->12.100 12.11 --> 12.110 12.111-->12.111

I've used the index function to append characters on the front of string, but his seems like the opposite problem. Hopefully this problem is not so trivial that it fails to illicit responses.

Thanks,

Mike Murff SLC, Utah

------------------------------------------------------------------------------ This message may contain confidential information, and is intended only for the use of the individual(s) to whom it is addressed.

=============================================================================


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