DATA Step, Macro, Functions and more

How to find the correct PAN #(ex: ABCDF1234J)in a given data.

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

How to find the correct PAN #(ex: ABCDF1234J)in a given data.

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


Accepted Solutions
Solution
‎12-25-2012 07:49 AM
Super User
Posts: 9,691

Re: How to find the correct PAN #(ex: ABCDF1234J)in a given data.

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


All Replies
Super User
Posts: 9,691

Re: How to find the correct PAN #(ex: ABCDF1234J)in a given data.

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

Contributor
Posts: 70

Re: How to find the correct PAN #(ex: ABCDF1234J)in a given data.

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

Solution
‎12-25-2012 07:49 AM
Super User
Posts: 9,691

Re: How to find the correct PAN #(ex: ABCDF1234J)in a given data.

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

Contributor
Posts: 70

Re: How to find the correct PAN #(ex: ABCDF1234J)in a given data.

Hi Ksharp,

Thank you..it is working

Regards,

Yaswanth J.

Super Contributor
Posts: 276

Re: How to find the correct PAN #(ex: ABCDF1234J)in a given data.

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 310 views
  • 4 likes
  • 3 in conversation