坚强别无选择 发表于 2019-7-2 13:21:37

sas,log,output,ods输出管理(html output_object output_statement)


1:改变log输出到指定外部文件
log一般输出在log窗口,使用printto过程可以改变其默认输出位置
proc printto log = "d:\log.txt" new; *将log输出到指定的文件中,new表示每次覆盖上一次,更多信息到时候查看帮助文档;
proc print data=sashelp.class;
proc printto; run; *恢复默认log输出;
2:改变output输出到指定外部文件
proc printto print='e:\log.txt';run;
proc freq data=sashelp.class;
table sex;
run;
proc printto;run;
/*不知为何输出不到外部文件,以后再检查*/
什么是ODS?
Output Delivery System

Ods有什么用?
determines where the output should go and what it should look like when it gets there.

理解Ods的基础是什么?
destinations:different types of ODS output
Template: is a set of instructions telling ODS how to format your data.

destinations:如果不指定输出目的地,那么默认为listing
下面是所有的输出目的地
LISTINGstandard SAS output
HTMLHypertext Markup Language
RTFRich Text Format
PRINTERhigh-resolution printer output2
PSPostScript
PCLPrinter Control Language
PDFPortable Document Format
OUTPUTSAS output data set
MARKUPmarkup languages including
XMLDOCUMENToutput document

Template = table template + style template
但是template的语法比较复杂,用已经设置好的内置类型就可以了
PROC TEMPLATE;
LIST STYLES;
RUN;

理解output object(简写为oo)
当sas从procedure中获取数据后,他会将data和table template组合成output object,对于一般过程来说只有一个output object,但对于含有by语句的程序来说,可以有很多,每个by组都可以有一个用ods trace statement来跟踪用ods select来选择
语法如下
ODS TRACE ON;
the PROC steps you want to trace go here
RUN;
ODS TRACE OFF;
日志对应的信息,证明确实有两个output object
ods trace off;
ods trace on;
proc means data=sashelp.class n mean maxdec=2;
      by sex;
     *ods select Means.ByGroup1.Summary;   /*这两句是我后面加进来的,运行程序是并不存在,表明选择需要输出的oo或需要排除的oo*/
     *ods exclude Means.ByGroup1.Summary;
run;


Output Added:
-------------
名称:      Summary
标签:      汇总统计量
模板:      base.summary
路径:      Means.ByGroup1.Summary
-------------
NOTE: 上述消息针对以下 BY 组:
      性别=男

Output Added:
-------------
名称:      Summary
标签:      汇总统计量
模板:      base.summary
路径:      Means.ByGroup2.Summary
-------------
NOTE: 上述消息针对以下 BY 组:
      性别=女

ods output statement
这条语句能输出任意对象到数据集,我现在不能经常用到,所以暂时不管。

ods html file='' style= ;
ods html close;
这两条语句对应出现,规定以html文件输出,以及输出的地方和style


3:利用ods改变输出路径
filename outp 'C:\Users\Administrator\Desktop\myTestForToday\test.html';

ods listing close; *改变默认输出路径listing;
ods html file=outp; *打开指定;
proc univariate data=sashelp.class;
    var weight;
run;
ods html close;
ods listing;

4:ods results on/off对应结果查看集
程序比较大时,尽量关闭results管道,不然会占用很多资源。

5:输出需要的对象ods trace on/label;
*列出过程中所有可以输出的模块;
ods trace on/label;
proc univariate data=sashelp.class;
    class sex;
    var   age;
run;
/*proc freq data=sashelp.class;*/
/*    table sex;*/
/*run;*/
ods trace off;


*其中一个模块的示例;
Output Added:
-------------
名称:      ExtremeObsselect后面的模块名
标签:      极值观测
模板:      base.univariate.ExtObs
路径:      Univariate.Age.男.ExtremeObs   路径可以确定要输出的模块
标签路径:'Univariate PROCEDURE'.'Age'.'Sex = 男'.'极值观测' 添加标签后才有。
页: [1]
查看完整版本: sas,log,output,ods输出管理(html output_object output_statement)