BookmarkSubscribeRSS Feed
dishant
Calcite | Level 5

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

10 REPLIES 10
RamKumar
Fluorite | Level 6

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

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

dishant
Calcite | Level 5

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.

gergely_batho
SAS Employee

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

dishant
Calcite | Level 5

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.

gergely_batho
SAS Employee

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

dishant
Calcite | Level 5

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

There is no such pattern given.

gergely_batho
SAS Employee

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ó

    RW9
    Diamond | Level 26 RW9
    Diamond | Level 26

    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;

    Loko
    Barite | Level 11

    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;

    stat_sas
    Ammonite | Level 13

    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;

    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
    • 10 replies
    • 1238 views
    • 0 likes
    • 6 in conversation