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-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!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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