UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS Code Fragments
Replacing Strings

* The example below shows how you can alter a string in a character variable ;
* It replaces , . or - with nothing ;
data temp;
input com $12.;
cards;
ANC, Inc
ANC. Inc
ANC Inc
ANC-Inc
Anc
;
run;

data temp2;
  set temp;
  rx=rxparse("$',.-' to ''"); /*define pattern*/
  mycom=compress(com);
  call rxchange(rx,999,mycom);
  comname=compress(mycom);
  drop mycom rx;
run;

proc print data=temp2;
run;
Obs    com         comname
 1     ANC, Inc    ANCInc
 2     ANC. Inc    ANCInc
 3     ANC Inc     ANCInc
 4     ANC-Inc     ANCInc
 5     Anc         Anc

How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California