简体   繁体   English

计算SAS中观测值的总组合

[英]calculate total combinations of observations in SAS

I have a variable with few values for that. 我有一个变量,几乎没有值。 Example: Var1 A,B,C,D,E,F,G,H 示例:Var1 A,B,C,D,E,F,G,H

How can i find the total 2 letter combinations possible? 我怎样才能找到总共2个字母的组合? eg: AB, AC, AD etc. 例如:AB,AC,AD等。

Here the list i have mentioned is small but in general I have a huge list and need to find total two letter combinations possible with all the values present for the variable. 在这里,我提到的列表很小,但是总的来说,我有一个庞大的列表,需要找到可能存在的所有两个字母组合以及变量的所有值。 Thanks 谢谢

A Cartesian join will give you every combination against every combination, so a self join here will give you all possibilities. 笛卡尔联接将为您提供每种组合的所有组合,因此此处的自我联接将为您提供所有可能性。 I usually use Proc SQL: 我通常使用Proc SQL:

 Proc sql;
    create table cartesian1 as
        select * from table1,table1;
 Quit;

Does this give you the table you want? 这会给您想要的桌子吗? I'm assuming that you want all 2 letter combinations rather than permutations (ie order is not relevant). 我假设您要所有2个字母组合而不是排列组合(即顺序不相关)。

data have;
input var1 $;
datalines;
A
B
C
D
E
F
G
H
;
run;

data want;
set have nobs=nobs;
length two_way $2;
do i=_n_+1 to nobs;
    set have (rename=(var1=temp)) point=i;
two_way=cats(var1,temp);
keep two_way;
output;
end;
run;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM