开发者

SAS/IML: creating a dataset from multiple matrices

Let's say I have a number of matrices in IML. They can be either numeri开发者_如何学运维c 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?


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜