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

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
Calcite | Level 5

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
Calcite | Level 5

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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