DATA Step, Macro, Functions and more

How to find fancy number from the variable

Reply
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

.....

Please help me out to finding the fancy numbers from my variable.

Your help will help me a lot.  thanks in advance.

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,

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.

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
    Super User
    Posts: 7,400

    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: 305

    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;

    Trusted Advisor
    Posts: 1,204

    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;

    Ask a Question
    Discussion stats
    • 10 replies
    • 353 views
    • 0 likes
    • 6 in conversation