在SAS中生成阵列的所有唯一排列 [英] Generate All Unique Permutations of an Array in SAS

查看:74
本文介绍了在SAS中生成阵列的所有唯一排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SAS中,如果我有类似以下的字符串或数组,

In SAS if I have a string or an Array like the following,

array x[4] $1 ('A' 'B' 'C' 'D');

我需要生成元素的所有唯一"排列,如下所示,

I need to generate all "Unique" permutations of the elements like the following,

[ABCD]
[ABC]
[BCD]
[ACD]
[ABD]
[AB]
[AC]
[AD]
[BC]
[BD]
[CD]
[A]
[B]
[C]
[D]

SAS中是否具有用于生成阵列的所有可能组合的功能?

Is there a function in SAS for generating all possible combinations of the array?

推荐答案

对此稍有不同,那就是使用 proc summary .

A slightly different take on this is to use proc summary.

创建一个虚拟数据集.将数组的每个元素分配给一个变量,这样我们就可以将其输入到 proc summary :

Create a dummy dataset. Assign each element of the array to a variable so we can feed it into proc summary:

data tmp;
  array arr[*] a b c d (1 1 1 1);
run;

运行 proc摘要.

proc summary data=tmp noprint missing;
  class a b c d;
  output out=combinations;
run;

您还可以在 proc summary 中使用 ways types 语句来限制所需的任何组合.

You can also use the ways or types statements in proc summary to limit any combinations you may want.

现在,这样做的有趣的副作用是,您也可以在输出数据集中获得 _type _ 列.在上面的示例中,将分配以下值:

Now the interesting side effect of doing this is that you get the _type_ column in the output dataset as well. In the example above the following values would be assigned:

D = 1
C = 2
B = 4
A = 8

因此,如果输出数据集中的 _type _ 值为13,则我们知道该行是通过组合A,B和D(8 + 4 + 1)生成的.

So if the _type_ value in the output dataset is 13, then we know that the row was generated by combining A, B and D (8 + 4 + 1).

这篇关于在SAS中生成阵列的所有唯一排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆