I like Chang's suggested code and, if you want, it would be simple to wrap it in a macro. E.g., the following uses the same structure (mostly) of the original:
[pre]
%macro replace (dataset = , search = , replace =, variable =, newlength = );
data &dataset. (drop = oldvar);
set &dataset. (rename=(&variable.=oldvar));
length &variable $&newlength.;
&variable. = prxchange("s|&search.|&replace.|", -1, oldvar);
run;
%mend replace;
data have;
informat aetext $50.;
input PTID AETEXT &;
cards;
110 ABD. CRAMPING
160 INTRA-ABD. ABSCESS ABD.
190 (L) ABD. PAIN
220 FOOT ULCER (L) FOOT
230 ABD. PAIN
360 (L) ELBOW CONTUSION
440 PAIN (L) KNEE
520 ACNE
520 TINGLING (L) FOOT
530 ASCITES ABD.
;
run;
%replace (dataset = have,
search = ABD.,
replace = ABDOMINAL,
variable = aetext,
newlength = 50)
[/pre]
HTH,
Art
> Here is one way. hth.
>
>
> style="color:#008000;font-family:Courier
> New;font-size:10pt;">/* test data */
> pan>
>
> style="color:#000080;font-family:Courier
> New;font-size:10pt;">data
> style="font-family:Courier
> New;font-size:10pt;"> one;
> old
> =
> style="color:#800080;font-family:Courier
> New;font-size:10pt;">"asdgdfgdg"
> style="font-family:Courier
> New;font-size:10pt;">;
>
> style="color:#000080;font-family:Courier
> New;font-size:10pt;">run
> style="font-family:Courier
> New;font-size:10pt;">;
>
>
> style="color:#008000;font-family:Courier
> New;font-size:10pt;">/* create a new&nb
> sp;var replacing dg with YY i
> n old */
>
> style="color:#000080;font-family:Courier
> New;font-size:10pt;">data
> style="font-family:Courier
> New;font-size:10pt;"> two;
>
> pan>set
> style="font-family:Courier
> New;font-size:10pt;"> one;
>
> pan>length
> style="font-family:Courier
> New;font-size:10pt;"> new $
> style="color:#008080;font-family:Courier
> New;font-size:10pt;">9
> style="font-family:Courier
> New;font-size:10pt;">;
> new
> = prxchange(
> style="color:#800080;font-family:Courier
> New;font-size:10pt;">"s|dg|YY|"
> style="font-family:Courier
> New;font-size:10pt;">, -
> style="color:#008080;font-family:Courier
> New;font-size:10pt;">1
> style="font-family:Courier
> New;font-size:10pt;">, old);
>
> style="color:#000080;font-family:Courier
> New;font-size:10pt;">run
> style="font-family:Courier
> New;font-size:10pt;">;
>
>
> style="color:#008000;font-family:Courier
> New;font-size:10pt;">/* check */
> />
>
> style="color:#000080;font-family:Courier
> New;font-size:10pt;">proc
> style="font-family:Courier
> New;font-size:10pt;">
> style="color:#000080;font-family:Courier
> New;font-size:10pt;">print
> style="font-family:Courier
> New;font-size:10pt;">
> style="color:#0000FF;font-family:Courier
> New;font-size:10pt;">data
> style="font-family:Courier
> New;font-size:10pt;">=two;
>
> style="color:#000080;font-family:Courier
> New;font-size:10pt;">run
> style="font-family:Courier
> New;font-size:10pt;">;
>
> style="color:#008000;font-family:Courier
> New;font-size:10pt;">/* on lst
> />
> Obs
> old &nb
> sp; new
> />
> 1 &n
> bsp; asdgdfgdg
> ;asYYdfgYY
> */
... View more