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

Hi,


How to find the correct PAN # in a given data.

data can be in any format..A PAN should be first 5 chars,fallowed by 4 digits and ends with char...need to create a flag where PAN is in correct FORMAT  on not.


data test;

input tt $10.

cards;

abcde1234f

bcdef2345g

bh4hg2351h

1235456797

;

run;

In my above data 1st and 2nd records are in correct format, other records should be flogged with "incorrect".  My question is that, i want data in correct format i.e 1st and 2nd obs.

can any one help, that should be  appreciated.

Thanks,

Yaswanth

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

or split it into three part to judge ,

data test;
input tt  $10.;
if length(tt) = 10 then do;
 if notalpha(substr(tt,1,5)) or notdigit(substr(tt,6,4)) or notalpha(substr(tt,10,1)) then found=0;else found=1;
end;
cards;
abcde1234f
bcdef2345g
bh4hg2351h
1235456797
;
run;

Ksharp

View solution in original post

5 REPLIES 5
Ksharp
Super User

It is easy for Perl Regular Expression.

data test;
input tt $10.;
pid=prxparse('/^[a-zA-Z]{5,5}\d{4,4}[a-zA-Z]$/');
if prxmatch(pid,tt) then found=1;else found=0;
drop pid;
cards;
abcde1234f
bcdef2345g
bh4hg2351h
1235456797
;
run;

Ksharp

yaswanthj
Fluorite | Level 6

Hi Ksharp,

Thanks For your quick reply..

is there any other ways to do this.. i was pretty new to  "prxparse" expressions. i can not able to understand the expression..

Thanks,

Yaswanth

Ksharp
Super User

or split it into three part to judge ,

data test;
input tt  $10.;
if length(tt) = 10 then do;
 if notalpha(substr(tt,1,5)) or notdigit(substr(tt,6,4)) or notalpha(substr(tt,10,1)) then found=0;else found=1;
end;
cards;
abcde1234f
bcdef2345g
bh4hg2351h
1235456797
;
run;

Ksharp

yaswanthj
Fluorite | Level 6

Hi Ksharp,

Thank you..it is working

Regards,

Yaswanth J.

kuridisanjeev
Quartz | Level 8

Hi Ksharp..

Bit Simplified your Solution..

data test;

input tt  $10.;

if Sum(notalpha(substr(tt,1,5)),notdigit(substr(tt,6,4)),notalpha(substr(tt,10,1))) then found=0;else found=1;

cards;

abcde1234f

bcdef2345g

bh4hg2351h

1235456797

abcde1234f8

;

run;

Proc print;

run;

Per my knowledge  "if length(tt) = 10 then do;" condition was not required in your program because  already  Length of the TT variable  mentioned  as  10 in input statement.:-)

Thanks & Regards..

Sanjeev.K

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
  • 5 replies
  • 2086 views
  • 4 likes
  • 3 in conversation