f



What's wrong with this: street_n=addr1_1|" "||addr2||" "||addr3||" "||addr4||" "||addr5

Hi,
I wanted to remove the first zero  from 0416 E. BAILEY  101, but not from
0 S 356 MADISON.
I ran the following code and I have problem with the line:
------------------------
street_n=addr1_1|" "||addr2||" "||addr3||" "||addr4||" "||addr5;
----------------------

My desired output is something like this under one single variable "street_n":
416 E. BAILEY  101
0S356 MADISON

Hope to get some help from out there.
Thanks,
Duckhye.


data a; input street $1-19;
cards;
0416 E. BAILEY  101
0 S 356 MADISON
;
run;

data b;set a;
addr1=put(left(scan(street, 1, ' ')), 10.);
addr2=put(left(scan(street, 2, ' ')), 10.);
addr3=put(left(scan(street, 3, ' ')), 10.);
addr4=put(left(scan(street, 4, ' ')), 10.);
addr5=put(left(scan(street, 5, ' ')), 10.);
If addr1 =:'0 ' then do;
street_n=INPUT(compress(addr1||addr2||addr3)||" "||compress(addr4)||" "||compress(addr5), $50.);
end;
else If addr1 ^=:'0 ' and addr1=:'0' then
do;
addr1_1=substr(addr1,2,length(addr1));
street_n=addr1_1|" "||addr2||" "||addr3||" "||addr4||" "||addr5;
end;
run;
0
dyang (97)
3/4/2004 6:55:20 PM
comp.soft-sys.sas 142828 articles. 3 followers. Post Follow

2 Replies
595 Views

Similar Articles

[PageSpeed] 51

If you run Version 9, use the CATX function instead.

On Thu, 4 Mar 2004 12:55:20 -0600, Duck-Hye Yang <dyang@CHAPINHALL.ORG>
wrote:

>Hi,
>I wanted to remove the first zero  from 0416 E. BAILEY  101, but not from
>0 S 356 MADISON.
>I ran the following code and I have problem with the line:
>------------------------
>street_n=addr1_1|" "||addr2||" "||addr3||" "||addr4||" "||addr5;
>----------------------
>
>My desired output is something like this under one single
variable "street_n":
>416 E. BAILEY  101
>0S356 MADISON
>
>Hope to get some help from out there.
>Thanks,
>Duckhye.
>
>
>data a; input street $1-19;
>cards;
>0416 E. BAILEY  101
>0 S 356 MADISON
>;
>run;
>
>data b;set a;
>addr1=put(left(scan(street, 1, ' ')), 10.);
>addr2=put(left(scan(street, 2, ' ')), 10.);
>addr3=put(left(scan(street, 3, ' ')), 10.);
>addr4=put(left(scan(street, 4, ' ')), 10.);
>addr5=put(left(scan(street, 5, ' ')), 10.);
>If addr1 =:'0 ' then do;
>street_n=INPUT(compress(addr1||addr2||addr3)||" "||compress(addr4)
||" "||compress(addr5), $50.);
>end;
>else If addr1 ^=:'0 ' and addr1=:'0' then
>do;
>addr1_1=substr(addr1,2,length(addr1));
>street_n=addr1_1|" "||addr2||" "||addr3||" "||addr4||" "||addr5;
>end;
>run;
0
3/4/2004 9:23:41 PM
Thank you for the code.  That's what I really wanted to see.
I have some problem in understanding the code: particularly,  ` '0'* <^w ?*> from your code  rx = rxparse("` '0'* <^w ?*> to =1");
I know the tag expression and *, but I do not understand the rest characters.  Can you explain it for me?

Many thanks,
Duckhye

>>> "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM> 03/04/04 01:36PM >>>
On Thu, 4 Mar 2004 12:55:20 -0600, Duck-Hye Yang <dyang@CHAPINHALL.ORG>
wrote:

>Hi,
>I wanted to remove the first zero  from 0416 E. BAILEY  101, but not from
>0 S 356 MADISON.
>I ran the following code and I have problem with the line:
>------------------------
>street_n=addr1_1|" "||addr2||" "||addr3||" "||addr4||" "||addr5;
>----------------------
>

Hi, Duck-Hye,

You need to add one more bar character after addr1_1 for the above line.

For removing the leading zeros, try the following rx solution.

Cheers,
Chang

<sasl:code>
/* test data */
options nocenter;
data one;
  length line $50;
  line = "0416 E. BAILEY  101"; output;
  line = "0016 E. BAILEY  101"; output;
  line = "0001 E. BAILEY  101"; output;
  line = "0 S 356 MADISON";     output;
  line = "00 S 356 MADISON";    output;
run;

data two;
  set one;
  if _n_ =1 then do;
   length new_line $50;
 /* remove any leading 0^s without immediately following non-white
space */
 drop rx;
 rx = rxparse("` '0'* <^w ?*> to =1");
 retain rx;
  end;
  call rxchange(rx, 1, line, new_line);
run;
proc print data=two;
run;
/* on lst
Obs           line                 new_line

 1     0416 E. BAILEY  101    416 E. BAILEY  101
 2     0016 E. BAILEY  101    16 E. BAILEY  101
 3     0001 E. BAILEY  101    1 E. BAILEY  101
 4     0 S 356 MADISON        0 S 356 MADISON
 5     00 S 356 MADISON       0 S 356 MADISON
*/
</sasl:code>
0
dyang (97)
3/4/2004 11:16:33 PM
Reply: