BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
willy0625
Calcite | Level 5

SAS users,

I would like to replace company type chracters such as LTD, limited, ltd. etc

So far I have done:

data test3;

set test2;

ocp=prxchange("s/([Pp][Tt][Yy] [Ll][Tt][Dd])|([Ll]imite)|([Ll]t)|([Pp]t)|([Pp][Tt][Yy] [Ll]imite) / /", -1, original_credit_provider);

*if _n_=68;

run;

At the moment, I cannot deal with the ones that ends with a ".". How would you modify the above regular expression paraemter

so that it can perform prxchange for values such as:

ABC Pty. Ltd. => ABC

ABC Pty. Ltd. => ABC

Also, is there something to ensure that this string replace is done from the right end of each string?

Many thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Alpay
Fluorite | Level 6

You may also use "i" option to make search case insensitive.

data x;

length original_credit_provider $32;

input original_credit_provider $1-32;

ocp=prxchange("s/PTY\.? (Limited|Ltd\.?)//i", -1, original_credit_provider);

datalines;

ABC Pty. Ltd.

ABC Pty. Limited

ABC Pty Limited

ABC Pty Ltd.

;

run;

View solution in original post

2 REPLIES 2
Ksharp
Super User

How about it.

data test2;
 input original_credit_provider & $20.;
cards;
ABC Pty. Ltd.
ABC Pty. Ltd.
;
run;
data test3;
set test2;
ocp=prxchange("s/([Pp][Tt][Yy]\.? [Ll][Tt][Dd]\.?)|([Ll]imite)|([Ll]t)|([Pp]t)|([Pp][Tt][Yy] [Ll]imite) / /", -1, original_credit_provider);
run;

Ksharp

Message was edited by: xia keshan

Alpay
Fluorite | Level 6

You may also use "i" option to make search case insensitive.

data x;

length original_credit_provider $32;

input original_credit_provider $1-32;

ocp=prxchange("s/PTY\.? (Limited|Ltd\.?)//i", -1, original_credit_provider);

datalines;

ABC Pty. Ltd.

ABC Pty. Limited

ABC Pty Limited

ABC Pty Ltd.

;

run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1882 views
  • 3 likes
  • 3 in conversation