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.
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
You can do:
if length(strip(translate(var,' ','0123456789')))=1 then put 'OK'; else put 'NOT-OK';
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.
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
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?
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.