2017-03-08 527 views
0

我正在SAS Enterprise Guide 6.1中运行以下SAS代码,以便为表中的所有变量获得null/not null的汇总统计信息。这是通过“结果”选项卡生成所需的信息,该选项卡为每个结果创建一个单独的表,显示空/非空频率和百分比。从SAS中的proc freq创建输出

我想要做的就是将结果放入一个输出数据集中,将所有变量和统计数据放在一张表中。

proc format; 
    value $missfmt ' '='Missing' other='Not Missing'; 
    value missfmt . ='Missing' other='Not Missing'; 
run; 
proc freq data=mydatatable; 
    format _CHAR_ $missfmt.; 
    tables _CHAR_/out=work.out1 missing missprint nocum; 
    format _NUMERIC_ missfmt.; 
    tables _NUMERIC_/out=work.out2 missing missprint nocum; 
run; 

out1out2正在生成到表中所示:

FieldName | Count | Percent 
Not Missing | Not Missing | Not Missing 

但是仅与每一个可变填充,并且没有被示出的频率计数。

我试图创建作为输出将表:

field | Missing | Not Missing | % Missing 
FieldName1 | 100 | 100 | 50 
FieldName2 | 3 | 97 | 3 
+1

这可能会有帮助,如果您将格式添加到'proc freq' +'table _all_;',它将生成所需的表格。 https://gist.github.com/statgeek/e0903d269d4a71316a4e – Reeza

回答

3

tables语句输出选项仅适用于要求最后表。 _CHAR_解析为(所有字符变量),但它们是单个表格,所以只能得到最后一个请求。

您可以通过以下两种方法中的任意一种。要么使用PROC TABULATE,这更容易处理变量列表;或使用ODS OUTPUT来获取proc频率输出。两种输出样式都需要一些工作才能进入您想要的结构。

ods output onewayfreqs=myfreqs; *use `ODS TRACE` to find this name if you do not know it; 
proc freq data=sashelp.class; 
    tables _character_; 
    tables _numeric_; 
run; 
ods output close; 
+0

谢谢,我是SAS新手,因此了解可用的不同选项很有帮助。我想出了一个使用'ods output'和'proc sql'组合的混乱解决方案! – joshi123