Hi All,
I want to find fancy numbers from the my variable. Below is the dummy example.
XYZ
123456
236514
412356
543216
621345
321456
.....
Please help me out to finding the fancy numbers from my variable.
Your help will help me a lot. thanks in advance.
Regards,
Dishant
what do you mean by fancy numbers? what is your desired output?
Can we imagine that your variable 'XYZ' is numeric?
Ram,
Please find my below explanation.
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.
Are you looking for numbers, that have digits: 1, 2,3, 4, 5, 6 in any order?
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.
And where is the pattern given? Is it the first row? Or you want to find all the "fancy groups" in your dataset?
Yes, I want to find all the "fancy groups" in your dataset.
There is no such pattern given.
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ó
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;
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;
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;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.