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

Hi, 

 

I have a variable as 'pr_ins_name' and example :

 

 

FASHION CO (M) BHD AS OWNER, LOOP
FASHION CO (M) BHD AS OWNER, LOOP INTER
ABC TECHONLOGY SDN BHD AS PRINCIPAL
ABD TECHONLOGY SDN BHD AS PRINCIPAL (AS MENTION
FLORA LIMITED

FLORA LTD
XYZ123 SDN BHD ON THE LIFE OF LKC
XYZ123 SDN BHD ON THE LIFE OF M
CAPTAIN APPAREL AS HIRER AND CONTRACTOR
YS ENTERPRISE AS HIRER AND HP DEVELOPMENT

 

I would like to remove those words (in Bold) :

1) contain "AS OWNER" , "AS PRINCIPAL" , "AS HIRER" , "ON THE LIFE OF" , "AS HIRER"

2) replace the "LIMITED" with "LTD"

 

How to combine above into one statement ?

 

 

data want;
set sasuser.name;


ins_name = substr (pr_ins_Name,1,find(pr_ins_name, ' AS OWNER')) ;
ins_name = substr (pr_ins_Name,1,find(pr_ins_name, ' AS HIRER')) ;
ins_name = substr (pr_ins_Name,1,find(pr_ins_name, ' AS PRINCIPAL')) ;
ins_name = substr (pr_ins_Name,1,find(pr_ins_name, ' ON THE LIFE OF')) ;

 


run;

 

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
pooiwan
Fluorite | Level 6

Thank you for your assistant. The program is worked and solved my problem. Have a nice day.

View solution in original post

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Something like:

data want;
  set sasuser.name;
  do i="AS_OWNER","AS PRINCIPAL"...;
    ins_name=tranwrd(ins_name,i,"");
  end;
run;

You could also put your strings in a dataset and use that.

pooiwan
Fluorite | Level 6

 

I am trying below statement:

 

data want;
set sasuser.name;
do i=' AS OWNER',' AS PRINCIPAL','ON THE LIFE OF',' AS HIRER';
ins_Name = substr (pr_ins_Name,1,find(pr_ins_name, i)) ;
end;
run;

 

Only observation contains 'AS HIRER' has executed. 

 

Message shown : 

NOTE: Invalid third argument to function SUBSTR at line 31 column 12.

 

Output :

 

FASHION CO (M) BHD AS OWNER, LOOP
FASHION CO (M) BHD AS OWNER, LOOP INTER
ABC TECHONLOGY SDN BHD AS PRINCIPAL
ABD TECHONLOGY SDN BHD AS PRINCIPAL (AS MENTION
FLORA LIMITED
FLORA LTD
XYZ123 SDN BHD ON THE LIFE OF LKC
XYZ123 SDN BHD ON THE LIFE OF M
CAPTAIN APPAREL 
YS ENTERPRISE

 

Thank you.

Patrick
Opal | Level 21

@pooiwan

Your approach as such seems more or less to work.

 

data sample;
  infile datalines truncover;
  input pr_ins_name $100.;
  pr_ins_name_orig=pr_ins_name;
  do search_str=' AS OWNER',' AS PRINCIPAL','ON THE LIFE OF',' AS HIRER';
    pr_ins_name = substr (pr_ins_name,1,find(pr_ins_name,search_str,'i'));
  end;

  datalines;
FASHION CO (M) BHD AS OWNER, LOOP
FASHION CO (M) BHD AS OWNER, LOOP INTER
ABC TECHONLOGY SDN BHD AS PRINCIPAL
ABD TECHONLOGY SDN BHD AS PRINCIPAL (AS MENTION
FLORA LIMITED
FLORA LTD
XYZ123 SDN BHD ON THE LIFE OF LKC
XYZ123 SDN BHD ON THE LIFE OF M
CAPTAIN APPAREL AS HIRER AND CONTRACTOR
YS ENTERPRISE AS HIRER AND HP DEVELOPMENT
;
run;

Capture.JPG

 

 

pooiwan
Fluorite | Level 6

Thank you for your assistant. The program is worked and solved my problem. Have a nice day.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

In future please mark the post which answered the question as the correct answer, not your thank you post.  Otherwise the answer post (which appears under the question) does not actually answer the question.

Patrick
Opal | Level 21

@pooiwan

Then mark the answer which you've used as the solution and not your answer to it.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You do however notice that your code is different to mine yes?

    ins_name=tranwrd(ins_name,i,"");

And yours:

ins_Name = substr (pr_ins_Name,1,find(pr_ins_name, i)) ;

 

Mine removes strings, yours does a substring.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 7997 views
  • 2 likes
  • 3 in conversation