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

Hello,

 

For a variable called Marketing_Source_Code, I want to exclude the code starting with a “P” followed by 3 digits. for example 'P121'.

I've used where Marketing_Source_Code like 'P___', but it will also delete the ones start with "P' followered by characters, for example 'PERN'.

 

How can I only exclude the code starting with a “P” followed by 3 digits.  I may need this in urgent but dont know how to search the result.

 

Thanks a lot.

1 ACCEPTED SOLUTION

Accepted Solutions
septemberbulb
Obsidian | Level 7

proc sql;

delete from plc_cust_income

where (MKT_SOURCE_CODE='RCS1' OR MKT_SOURCE_CODE='BFCE' OR MKT_SOURCE_CODE='EXEM' OR (MKT_SOURCE_CODE like "P%" and anyalpha(substr(MKT_SOURCE_CODE,2,3))=0)) 😉

 

Is that right?

thanks

View solution in original post

8 REPLIES 8
Shmuel
Garnet | Level 18

You can do:

 

if length(strip(translate(var,' ','0123456789')))=1 then put 'OK';  else put 'NOT-OK';

NicolasRobert
SAS Super FREQ

Hello,

 

ANYDIGIT might help in that case.

 

data b ;
set a ;
where not(a like "P%" and anydigit(a) in (2,3,4)) ;
run ;

 

---Update---

Well, it is more tricky than I thought...

This one should work better:

 

data b ;
set a ;
where not(a like "P%" and anyalpha(substr(a,2,3))=0) ;
run ;

 

 

Nicolas.

Nicolas is an Advisory Technical Architect in the Global Enablement and Learning (GEL) Team within SAS Customer Success Division
septemberbulb
Obsidian | Level 7

proc sql;

delete from plc_cust_income

where (MKT_SOURCE_CODE='RCS1' OR MKT_SOURCE_CODE='BFCE' OR MKT_SOURCE_CODE='EXEM' OR (MKT_SOURCE_CODE like "P%" and anyalpha(substr(MKT_SOURCE_CODE,2,3))=0)) 😉

 

Is that right?

thanks

Astounding
Opal | Level 21

Some relevant questions:

 

1. Is your variable always 4 characters long?

 

2. If it is only 3 characters long in some cases, how should P12 be handled?

Astounding
Opal | Level 21

OK.  It's possible that some of the earlier solutions posted by others are working.  Here's a DATA step statement that I know works when you always have four characters:

 

if Marketing_Source_Code =: 'P' and input(substr(Marketing_Source_Code, 2), ??3.) > . then delete;

SAS INNOVATE 2024

innovate-wordmarks-white-horiz.png

SAS is headed back to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team.

Interested in speaking? Content from our attendees is one of the reasons that makes SAS Innovate such a special event!

Submit your idea!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 8 replies
  • 779 views
  • 0 likes
  • 4 in conversation