Creating All Possible Combinations in a Table Using SAS

前端 未结 3 1456
一生所求
一生所求 2020-12-11 09:16

I have a table with four variables and i want the table a table with combination of all values. Showing a table with only 2 columns as an example.

NAME    AM         


        
3条回答
  •  自闭症患者
    2020-12-11 09:52

    Here's a variation on @JustinJDavies's answer, using an explicit CROSS JOIN clause:

    data have;
      input NAME $ AMOUNT  COUNT;
      datalines;
    RAJ     90  1
    RAVI    20  4
    JOHN    30  5
    JOSEPH  40  3
    run;
    
    PROC SQL;
      create table combs as
        select * 
          from have(keep=NAME)
            cross join have(keep=AMOUNT)
            cross join have(keep=COUNT)
          order by name, amount, count;
    QUIT;
    

    Results:

    NAME AMOUNT COUNT 
    JOHN 20     1 
    JOHN 20     3 
    JOHN 20     4 
    JOHN 20     5 
    JOHN 30     1 
    JOHN 30     3 
    JOHN 30     4 
    JOHN 30     5 
    ...
    

提交回复
热议问题