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 (May 1999, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sat, 29 May 1999 20:46:48 +0100
Reply-To:   Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Subject:   Re: How do I remove these characters?
In-Reply-To:   <375025C5.D395594D@agctr.lsu.edu>

OK Use the power of the data step to read with INPUT like "near-magic" !

use input @1 @'t' dnumber 3. to jump and read the last 3 digits in dsn

read those % values with the percent. informat

read the values in parenthesis using the comma. informat

A clip from an old favourite tsnote (TS486.txt) COMMAw.d removes commas, blanks, dollar and percent signs, dashes and right parentheses, and translates left parentheses to minus signs $1,000,000 | comma10. | 1000000 (1,000,000)| comma11. |-1000000

e.g. 478 data dd1; 479 infile cards TRUNCOVER; 480 informat triplnd diplnds comma12. perD perT percent8.; 481 input dsn $ triplnd diplnds PerD DCnt PerT TCnt 482 @1 @'t' dnumber 3. ; 483 if _n_ = 1 then 484 put "dsn dnumber triplnd diplnds Perd DCnt Pert Tcnt"; 485 put (dsn dnumber triplnd diplnds Perd DCnt Pert Tcnt) 486 ( $8. 4. 2*negparen9. percent8.2 5. percent8.2 5. ); 487 cards;

dsn dnumber triplnd diplnds Perd DCnt Pert Tcnt 100%t001 1 0 (20) 1.64% 35 98.36% 2099 100%t002 2 0 (20) 2.22% 52 97.78% 2288 100%t003 3 0 (20) 1.21% 27 98.79% 2208 95%t001 1 (1) (19) 12.92% 290 87.08% 1954 95%t002 2 (1) (19) 10.82% 240 89.18% 1978 95%t003 3 (1) (19) 11.86% 267 88.14% 1985 90%t001 1 (2) (18) 14.25% 301 85.75% 1811 90%t002 2 (2) (18) 12.91% 270 87.09% 1822 90%t003 3 (2) (18) 14.95% 310 85.05% 1764 NOTE: The data set WORK.DD1 has 9 observations and 8 variables. NOTE: The DATA statement used 0.05 seconds.

(Hopefully the put statement isn't OTT)

If appropriate, you could reverse the negative values assumed for () by the comma. informat.

Did you want it all numeric ?

Anthony Kilili <akilili@AGCTR.LSU.EDU> writes >I need help!! > >I have a less than 'clean' dataset from which I would like to remove >the parenthesis >from variable Dnumber and convert the enclosed numbers into two >numeric variables Tripinds and Dipinds...the code below is as far as I >got , what I'm I missing?? > >data dd1; >length dsn $ 8 Dnumber $ 9 val $3; >input dsn $ @10 Dnumber $char9. @24 PerD $ DCnt PerT $ TCnt; > >l=length(Dnumber); >i=index(dnumber,"T"); >val=right(Substr(dnumber,1,(i-1))); >TripInds=Input(val,3.); >Val=right(substr(dnumber,(i+2), (l-i-2))); >DipInds=input(val,3.); >drop i l val dnumber; > >cards; > >100%t001 (0) (20) 1.64% 35 98.36% 2099 >100%t002 (0) (20) 2.22% 52 97.78% 2288 >100%t003 (0) (20) 1.21% 27 98.79% 2208 > > >95%t001 (1) (19) 12.92% 290 87.08% 1954 >95%t002 (1) (19) 10.82% 240 89.18% 1978 >95%t003 (1) (19) 11.86% 267 88.14% 1985 > >90%t001 (2) (18) 14.25% 301 85.75% 1811 >90%t002 (2) (18) 12.91% 270 87.09% 1822 >90%t003 (2) (18) 14.95% 310 85.05% 1764

-- Peter Crawford (_knowledge_ is a poor substitute for *real* experience, but they make a great team)


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