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
PROC Star

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
PROC Star

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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

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