BookmarkSubscribeRSS Feed
seohyeonjeong
Obsidian | Level 7

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.

 

 

3 REPLIES 3
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

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;

PaigeMiller
Diamond | Level 26
if notalpha(contractno)=4 and substr(contractno,4,3)='098' then delete;
--
Paige Miller
Patrick
Opal | Level 21

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;

Patrick_0-1647290353149.png

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 468 views
  • 1 like
  • 4 in conversation