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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.