Date: Wed, 23 May 2007 01:20:17 -0700
Reply-To: barry.debenham@TALK21.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: barry.debenham@TALK21.COM
Organization: http://groups.google.com
Subject: Re: scanning right most value and change
In-Reply-To: <200705222148.l4MIor6t030185@malibu.cc.uga.edu>
Content-Type: text/plain; charset="iso-8859-1"
On 22 May, 22:48, hari_s_n...@YAHOO.COM (Hari Nath) wrote:
> Hi all,
> i have this program to read from a text file and then change the right
> most value to a 100.....am close but not successful.....can someone point
> me in the right way....am using sas 8.2 windows.....
>
> many thanks,
> hari
>
> ****prog************;
> Data have ;
> input textcol $10. cell1 $40. ;
> cell1 = tranwrd(cell1, scan (cell1,8, '() '),'100');
>
> cards ;
>
> total_1 0( 0.0) 3(30.8) 0( 0.0) 3(30.8)
> total_2 0( 0.0) 5(38.5) 0( 0.0) 5(38.5)
>
> ;
> run ;
>
> *********current output ;
> total_1 0( 0.0) 3(100) 0( 0.0) 3(100)
> total_2 0( 0.0) 5(100) 0( 0.0) 5(100)
>
> *********desired output ;
> total_1 0( 0.0) 3(30.8) 0( 0.0) 3(100)
> total_2 0( 0.0) 5(38.5) 0( 0.0) 5(100)
Hari,
Perahps you'd like to do the following. I've taken the last word from
the string and changed its contents before replacing it back into the
string.
DATE have ;
INPUT textcol $10.
cell1 $40. ;
LENGTH last $10;
DROP last llast len i;
len = LENGTH(cell1);
last = TRIM(LEFT(SCAN(cell1,-1,' ')));
llast = LENGTH(last);
i = INDEX(last,'(');
SUBSTR(last,i+1,llast) = SUBSTR('100) ',1,llast-1);
SUBSTR(CELL1,len-llast+1,llast) = last;
CARDS ;
total_1 0( 0.0) 3(30.8) 0( 0.0) 3(30.8)
total_2 0( 0.0) 5(38.5) 0( 0.0) 5(38.5)
;
RUN;
PROC PRINT output follows.
textcol cell1
total_1 0( 0.0) 3(30.8) 0( 0.0) 3(100)
total_2 0( 0.0) 5(38.5) 0( 0.0) 5(100)
I hope this is useful.
Regards,
Barry D
|