Hi everyone,
I want to select the data from the table which has a ContractNo column.
In this column, values are consist of numbers and alphabets.
The length of each row is not the same, but it has 11 to 13 letters.
Condition for subtraction is
ContractNo without the first three letters are Alphabet characters and the next three letters are not 098.
For example,
this kind of data must not be selected.
ABC098LIOPU
EFD0981234511
The data below must be selected.
1A20982345
1230986754
ADBDEF0981
If I could get any help, I will appreciate it.
Have you thought of using the COMPRESS() function with the third parameter 'KA' (keep alphabet characters)? This line of code in a DATA step might work:
if length(compress(substr(var, 1, 3), , 'ka')) = 3 and substr(var, 4, 3) = '098' then delete;
if notalpha(contractno)=4 and substr(contractno,4,3)='098' then delete;
Or here an approach using a regular expression.
data have;
infile datalines truncover;
input contractNo $13.;
datalines;
ABC098LIOPU
EFD0981234511
1A20982345
1230986754
ADBDEF0981
;
data want;
set have;
if prxmatch('/^[a-z]{3}098/oi',strip(contractNo)) then delete;
run;
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.