如何访问存储在SAS proc的输出中的数据

时间:2013-02-21 06:48:02

标签: sas

有几次,我需要在SAS中运行一个程序,然后保存输出变量以供另一个程序(MATLAB)访问。这很容易,例如:

proc genmod order=data;
    class X Y Z;
    output out= gmout1 prob = PRED;
    model count=X Y Z /dist=poi pred;
run; *mutual independence;
proc export data = work.gmout1
    outfile = "...\genmodout1.txt"
    dbms = csv replace;
run;

第3行中的output out= gmout1将proc genmod导出的任何变量保存到名为gmout1的库表中。

我目前的需求是能够访问SAS本身内存储在gmout1中的一些数据。应该很容易,但我的搜索没有发现任何有用的东西。

1 个答案:

答案 0 :(得分:1)

您的数据集gmout1可以用作使用data选项的其他过程的输入。例如,如果要打印这些:

proc print data=gmout1;
var _all_;
run;

您还可以使用set语句通过数据步骤(在SAS中进行大多数编程)对数据进行修改。例如,如果你有一个变量" fit"并且您需要将其重新编码为x100,您可以这样做:

data gmout2; *creates new dataset gmout2;
set gmout1; *use the dataset gmout1;
new_fit = fit * 100;*creates new variable new_fit as 100 times fit;
run;

要将特定变量(或多个变量)导出到文本文件,您有多个选项。最简单的:

data _null_;
set gmout1;
file "c:\temp\myfile.csv" dlm=',' lrecl=32767 dsd;
if dimension="Value" and dimension2="Value";
put
variable1_numeric
variable2_character $
variable3_numeric
;
run;

我注意到你提到了矩阵 - 技术上基础的SAS不能用矩阵操作,只用数据集(基本上是数据行)。 SAS / IML是矩阵语言;它的用法类似于R,并允许使用通用矩阵语法。