SAS/IML:从多个矩阵创建数据集

发布于 2024-10-17 13:20:40 字数 354 浏览 2 评论 0原文

假设我有许多 IML 矩阵。它们可以是数字或字符。我将如何利用它们创建单个 SAS 数据集?

我尝试了类似的方法

n = {1 2 3, 4 5 6};      /* 2 x 3 numeric */
c = {'a' 'b', 'c' 'd'};  /* 2 x 2 character */
dsvars = {n c};
create dat var dsvars;   /* should be a 2-obs, 5-variable dataset */
append;

,但这将 n 和 c 转换为列向量并导出它们,这不是我想要的。我应该分别导出 n 和 c 并将它们合并到 DATA 步骤中吗?

Let's say I have a number of matrices in IML. They can be either numeric or character. How would I go about creating a single SAS dataset out of them?

I tried something like

n = {1 2 3, 4 5 6};      /* 2 x 3 numeric */
c = {'a' 'b', 'c' 'd'};  /* 2 x 2 character */
dsvars = {n c};
create dat var dsvars;   /* should be a 2-obs, 5-variable dataset */
append;

but this turns n and c into column vectors and exports those, which is not what I want. Should I export n and c separately and merge them in a DATA step instead?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情栀口红 2024-10-24 13:20:40

当 n 和 c 是向量时,您的方法有效。当它们是矩阵时,有几种方法可以做到这一点。我喜欢使用 CREATE FROM 和 APPEND FROM 语法,并将数字矩阵和字符矩阵写入单独的数据集,然后再合并:

proc iml;
n = {1 2 3, 4 5 6};      /* 2 x 3 numeric */
c = {'a' 'b', 'c' 'd'};  /* 2 x 2 character */

nNames = "n1":"n3";
cNames = "c1":"c2";
create ndat from n[colname=nNames]; 
append from n;
create cdat from c[colname=cNames]; 
append from c;
quit;

data dat;
   merge ndat cdat;
run;
proc print;run;

Your approach works when n and c are vectors. When they are matrices, there are a couple of ways to do this. I like to use the CREATE FROM and APPEND FROM syntax, and write the numerical and character matrices to separate data sets that I later merge:

proc iml;
n = {1 2 3, 4 5 6};      /* 2 x 3 numeric */
c = {'a' 'b', 'c' 'd'};  /* 2 x 2 character */

nNames = "n1":"n3";
cNames = "c1":"c2";
create ndat from n[colname=nNames]; 
append from n;
create cdat from c[colname=cNames]; 
append from c;
quit;

data dat;
   merge ndat cdat;
run;
proc print;run;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文