BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
farshidowrang
Quartz | Level 8

Dear friends;

 

I perform a quality check of the names of the oil wells.

 

I have two different expressions in a special sequence for my oil wells names like these:

 

Expression 1:

Anydigit/Anydigit- Anysingleletter-Anydigit

For example:

123/445-A-123

1266/92-D-110

 

Expression 2:

Anydigit/Anydigit- Anydigit

For example:

7623/67653-222

29/33-12

 

Then I have a list of oil wells names which I like to check their quality. If they don’t match the sequence of the Expression 1 or Expression 2 then a flag will show that they are not invalid. Please look at the following table:

 

WELL FLAG
3923/2169-A-2130 VALID
227/3437-D-1195 VALID
27/190-F-4031 VALID
686/34-H-1890-D NOT VALID
1562/1802-12 VALID
4748/4652 -E -2875 VALID
4648/1008 -12 -870 NOT VALID
5118/834-A-4474 VALID
2669/1701-405 VALID
1952/2094-5105 VALID
1280/4359 -U -4322-F NOT VALID
1058/355 -I -462 VALID
3858/689-P-GX NOT VALID
2838/3002-W-2948 VALID

 

I need to have a SAS data step to give me the quality flag. Can you please help me with it?

 

Thank you very much in advance!

 

Best regards

 

Farshid Owrang 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Do like this. 

 

data have;
input well :$50.;
datalines; 
3923/2169-A-2130 
227/3437-D-1195 
27/190-F-4031 
686/34-H-1890-D 
1562/1802-12 
4748/4652 -E -2875 
4648/1008 -12 -870 
5118/834-A-4474 
2669/1701-405 
1952/2094-5105 
1280/4359 -U -4322-F
1058/355 -I -462 
3858/689-P-GX 
2838/3002-W-2948 
;

data want;
   set have;
   flag='Not Valid';
   if prxmatch('/\d+\/\d+-[A-Za-z]-\d+/', well) | 
      prxmatch('/\d+\/\d+-\d+/', well) then flag='Valid';
run;

  

Result: (Your 12'th obs in your desired results does not comply with your logic)

 

well              flag 
3923/2169-A-2130  Valid 
227/3437-D-1195   Valid 
27/190-F-4031     Valid 
686/34-H-1890-D   Valid 
1562/1802-12      Valid 
4748/4652         Not Valid 
4648/1008         Not Valid 
5118/834-A-4474   Valid 
2669/1701-405     Valid 
1952/2094-5105    Valid 
1280/4359         Not Valid 
1058/355          Not Valid 
3858/689-P-GX     Not Valid 
2838/3002-W-2948  Valid 

 

 

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Do like this. 

 

data have;
input well :$50.;
datalines; 
3923/2169-A-2130 
227/3437-D-1195 
27/190-F-4031 
686/34-H-1890-D 
1562/1802-12 
4748/4652 -E -2875 
4648/1008 -12 -870 
5118/834-A-4474 
2669/1701-405 
1952/2094-5105 
1280/4359 -U -4322-F
1058/355 -I -462 
3858/689-P-GX 
2838/3002-W-2948 
;

data want;
   set have;
   flag='Not Valid';
   if prxmatch('/\d+\/\d+-[A-Za-z]-\d+/', well) | 
      prxmatch('/\d+\/\d+-\d+/', well) then flag='Valid';
run;

  

Result: (Your 12'th obs in your desired results does not comply with your logic)

 

well              flag 
3923/2169-A-2130  Valid 
227/3437-D-1195   Valid 
27/190-F-4031     Valid 
686/34-H-1890-D   Valid 
1562/1802-12      Valid 
4748/4652         Not Valid 
4648/1008         Not Valid 
5118/834-A-4474   Valid 
2669/1701-405     Valid 
1952/2094-5105    Valid 
1280/4359         Not Valid 
1058/355          Not Valid 
3858/689-P-GX     Not Valid 
2838/3002-W-2948  Valid 

 

 

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
  • 2 replies
  • 424 views
  • 2 likes
  • 2 in conversation