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

Dear @ChrisNZ 

 

I think your code works well. However, 1, I worry about the presence of ' ' and " " following 'COMPANY'

 

for example  

 

data T;
  input NAME_S22 :&$200.;
cards;
3M COMPANY (MINNESOTA MINING AND MANUFACTURING COMPANY)
3M COMPANY 'MINNESOTA MINING AND MANUFACTURING COMPANY'
3M COMPANY "MINNESOTA MINING AND MANUFACTURING COMPANY"
run;

 I expect to get 

NAME_S22NAME_B
3M COMPANY (MINNESOTA MINING AND MANUFACTURING COMPANY)3M CO (MINNESOTA MINING AND MANUFACTURING COMPANY)
3M COMPANY 'MINNESOTA MINING AND MANUFACTURING COMPANY'3M CO 'MINNESOTA MINING AND MANUFACTURING COMPANY'
3M COMPANY "MINNESOTA MINING AND MANUFACTURING COMPANY"3M CO "MINNESOTA MINING AND MANUFACTURING COMPANY"

 

I expect to use (\'[^']*\')* and (\"[^']*\")* based on the code which you taught me(i.e., (\([^)]*\))*). However it out of work in the regex in SAS.

 

2.Besides, 

For the value 'ARCH TIMBER PROTECTION LIMITED, A PRIVATE LIMITED COMPANY ORGANISED UNDER THE LAWS OF THE UNITED KINDGOM' I expect to get the value of 'NAME_B' which stopping the process when meeting the first company suffix.

 

 

NAMEname_Bname_address
ARCH TIMBER PROTECTION LTD A PRIVATE LTD CO ORGANISED UNDER THE LAWS OF THE UNITED KINDGOMARCH TIMBER PROTECTION LTD A PRIVATE LTD CO ORGANISED UNDER THE LAWS OF THE UNITED KINDGOM

 

Could you please give me some suggestion about these two questions?

ChrisNZ
Tourmaline | Level 20
I can't look now but try:- to test your expression on the regex101.com website- learn how to add quotes in strings if you don't know how. Hint: double them.
ChrisNZ
Tourmaline | Level 20

@Alexxxxxxx  What have you learnt?

data WANT;
  set HAVE;
  NAME1=prxchange('s/( ?,?L ?\.? ?T ?\.? ?D ?\.? ?,?)/ LTD /'     ,1,NAME );
  NAME2=prxchange('s/( ?,?C ?\.? ?O ?\.? ?,?)/ CO /'              ,1,NAME1);
  NAME3=prxchange('s/(.*)( CO LTD | LTD CO | LTD | CO )(.*)/$1$2/',1,NAME2);
  NAME4=prxchange('s/(.*)( CO LTD | LTD CO | LTD | CO ) *(.*)/$3/',1,NAME2);
run;

NAME3 NAME4
AAA LTD NEW YORK
AAA LTD NEW YORK
AAA LTD LONDON
AAA LTD CO TOKYO
AAA CO LTD TOKYO

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 2360 views
  • 5 likes
  • 2 in conversation