Contributor
Posts: 52

# How to find fancy number from the variable

Hi All,

I want to find fancy numbers from the my variable. Below is the dummy example.

XYZ

123456

236514

412356

543216

621345

321456

.....

Regards,

Dishant

Regular Contributor
Posts: 168

## Re: How to find fancy number from the variable

what do you mean by fancy numbers?  what is your desired output?

Can we imagine that your variable 'XYZ' is numeric?

Contributor
Posts: 52

## Re: How to find fancy number from the variable

Ram,

Dummy Data :

XYZ

123456

236514

454732

412356

947284

543216

621345

495345

321456

......

My Desired Output :

XYZ

123456

236514

412356

543216

621345

321456

.....

Fancy number means looks Same only pattern will differ.

If any concerns please let me know.

SAS Employee
Posts: 340

## Re: How to find fancy number from the variable

Are you looking for numbers, that have digits: 1, 2,3, 4, 5, 6 in any order?

Contributor
Posts: 52

## Re: How to find fancy number from the variable

Correct.

But not only 1,2,3,4,5,6, It can be any number. Likewise see the below one.

XYZ

789123

897321

137892

...

So It want to show those Observations who having different pattern but same Numbers.

SAS Employee
Posts: 340

## Re: How to find fancy number from the variable

And where is the pattern given? Is it the first row?   Or you want to find all the "fancy groups" in your dataset?

Contributor
Posts: 52

## Re: How to find fancy number from the variable

Yes, I want to find all the "fancy groups" in your dataset.

There is no such pattern given.

SAS Employee
Posts: 340

## Re: How to find fancy number from the variable

data have;

input XYZ;

datalines;

123456

236514

454732

412356

947284

543216

621345

495345

321456

;

run;

data tmp(keep=position XYZ key );

set have;

position=_n_;

length key \$ 6;

array digits[6] \$ 1;

do i=1 to dim(digits);

digits=substr(put(XYZ,6.),i,1);

end;

call sortc(of digits

• );
•   key=cats(of digits

• );
• run;

proc sort data=tmp out=want;

by key;

run;

Message was edited by: Gergely Bathó

Super User
Posts: 9,599

## Re: How to find fancy number from the variable

One suggestion, if you want to pull out sequences where the numbers 1-6 appear in any order, why not generate a dataset with all the possibilities, then do a where in that list:

data have;
input XYZ;
datalines;
123456
236514
454732
412356
947284
543216
621345
495345
321456
;
run;

data sequence;
seq=111111;
do until (seq=666666);
output;
seq=seq+1;
end;
run;

proc sql;
create table WANT as
select  *
from    WORK.HAVE
where   XYZ in (select distinct SEQ from WORK.SEQUENCE);
quit;

Super Contributor
Posts: 319

## Re: How to find fancy number from the variable

Hello,

One solution:

data have;
input XYZ;
datalines;
123456
236514
454732
412356
947284
543216
621345
495345
321456
;

data want;
set have;
do i=1 to 6;
if find(put(xyz,6.),put(i,1.)) = 0 then do;goto pass;end;
end;

output;

pass: ;
run;

Posts: 1,270

## Re: How to find fancy number from the variable

data want(drop=i cum);

set have;

cum=0;

do i=1 to 6;

cum + input(substr(put(xyz,6.),i,1),1.);

end;

if cum=21;

run;

Discussion stats
• 10 replies
• 410 views
• 0 likes
• 6 in conversation