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

Hi I need some help. I have the variable like site with values

Site

CT-BENGALURU-J.P.NAGAR

CT-BENGALURU-ORION MALL

CT-BENGALURU-SOUL SPACE SPIRIT

CT-MUMBAI-GOREGAON-OBEROI MALL

CT-PUNE-ASCENT MALL

CT-PUNE-MSM PARANJAPE MALL-KARVE ROAD

I want output like 

J.P.NAGAR

ORION MALL

SOUL SPACE SPIRIT

OBEROI MALL

ASCENT MALL

PARANJAPE MALL

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input Site $80.;
length want $ 80;
pid=prxparse('/\w+\s+MALL/i');
if prxmatch(pid,site) then do;
 call prxsubstr(pid,site,p,l);
 want=substr(site,p,l);
 end;
 else want=scan(site,-1,'-');
drop p l;
cards;
CT-BENGALURU-J.P.NAGAR
CT-BENGALURU-ORION MALL
CT-BENGALURU-SOUL SPACE SPIRIT
CT-MUMBAI-GOREGAON-OBEROI MALL
CT-PUNE-ASCENT MALL
CT-PUNE-MSM PARANJAPE MALL-KARVE ROAD
;
run;

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

I can't see a consistent rule here.

Usually it's the last "word" of those separatd by hyphens, but in the last line it is the second (and not even the whole second) and not the last. Without a consistent rule, no algorithm can be built.

venkatnaveen
Obsidian | Level 7

Actually there is data inconsistency.

LinusH
Tourmaline | Level 20

Looks like addresses, right?

Like @Kurt_Bremser said, there seems not be a clear rule.

That leaves us to do data standardization.

And I suspect that addresses are available in the SA Data Quality Base, India edition, contained in the data flux product(s).

Data never sleeps
Astounding
PROC Star

Here are some statements that approximate what you are trying to do:

 

new_site = scan(site, 3, '-');

 

new_site = scan(site, -1, '-');

 

The reason I say "approximate" is because you have rules in your head that are not part of the program.  For example, consider:

 

CT-PUNE-MSM PARANJAPE MALL-KARVE ROAD

 

Why should the result be PARANJAPE MALL instead of MSM PARANJAPE MALL?  You have some rules about that, but all of your rules have to be made known in order to incorporate them into the program.

 

Good luck.

 

Ksharp
Super User
data have;
input Site $80.;
length want $ 80;
pid=prxparse('/\w+\s+MALL/i');
if prxmatch(pid,site) then do;
 call prxsubstr(pid,site,p,l);
 want=substr(site,p,l);
 end;
 else want=scan(site,-1,'-');
drop p l;
cards;
CT-BENGALURU-J.P.NAGAR
CT-BENGALURU-ORION MALL
CT-BENGALURU-SOUL SPACE SPIRIT
CT-MUMBAI-GOREGAON-OBEROI MALL
CT-PUNE-ASCENT MALL
CT-PUNE-MSM PARANJAPE MALL-KARVE ROAD
;
run;
venkatnaveen
Obsidian | Level 7

Thanks a lot.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 1913 views
  • 2 likes
  • 5 in conversation