您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 经营企划 > SAS-report过程介绍
PROCREPORT基础一、PROCREPORT格式:PROCREPORTdata=SAS-data-setoptions;COLUMNSvariable_1….variable_n;DEFINEvariable_1;DEFINEvariable_2;...DEFINEvariable_n;COMPUTEblocksBREAK…;RBREAK…;RUN;COLUMNS:指定输出到报表的列DEFINE:上述列的格式等COMPUTE:计算模块BREAK/RBREAK:生成合计,或报表其它类型的格式。PROCREPORT的选项Options有很多,下面介绍几个常用的:DATA=指定做报表的数据集PROMPT=PROMPT模式NOWINDOWS=不输出到结果REPORT=指定一个存储的报表来生成新报表OUTREPT=指定新路径来存放报表OUT=建立新数据集HEADLINE在报表变量标题和内容间生成一个水平分隔线HEADSKIP在报表变量标题和内容间生成一行空格2先生成一个基本的报表先生成数据:datamnthly_sales;lengthzip$5cty$8var$10;inputzip$cty$var$sales;labelzip=ZipCodecty=Countyvar=Varietysales=MonthlySales;datalines;52423ScottMerlot186.52423ScottChardonnay156.6152423ScottZinfandel35.552423ScottMerlot55.352388ScottMerlot122.8952388ScottChardonnay78.2252388ScottZinfandel15.452200AdamsMerlot385.5152200AdamsChardonnay24652200AdamsZinfandel151.152200AdamsChardonnay76.2452199AdamsMerlot233.0352199AdamsChardonnay185.2252199AdamsZinfandel95.84;run;ProcReport生成最基本的报表:procreportdata=mnthly_salesheadlineheadskip;title1SimpleReport;columnctyzipvarsales;definecty/displaywidth=6'County/Name';definezip/display;definevar/display;definesales/displayformat=6.2width=10;run;这里的define后面的’/’,其后面有很多选项来对变量格式,输出方式等进行设置,其选项如下:GROUP:分组显示DISPLAY:一般显示ANALYSIS:其值用于计算或统计ORDER:按其值排序显示ACROSS:交叉显示COMPUTED:其值在compute块里计算得到结果:3使用order,按指定变量名排序显示procreportdata=mnthly_salesheadlineheadskip;title1SimpleReport;columnctyzipvarsales;definecty/orderwidth=6'County/Name';definezip/display;definevar/display;definesales/displayformat=6.2width=10;run;结果:4group分组显示procreportdata=mnthly_salesnofsheadlineheadskip;title1SimpleReport;columnctyzipvarsales;definecty/groupwidth=6'County/Name';definezip/group;definevar/grouporder=freqdescending;definesales/displayformat=6.2width=10;run;结果:5analysis,统计量求和procreportdata=mnthly_salesnofsheadlineheadskip;title1SimpleReport;columnctyzipsales;definecty/groupwidth=6'County/Name';definezip/group;definesales/analysissumformat=6.2width=10;run;结果:6求多个统计量procreportdata=mnthly_salesnofsheadlineheadskip;title1SimpleReport;columnctyzipsalessales=mean_sales;definecty/groupwidth=6'County/Name';definezip/group;definesales/analysissumformat=6.2width=10'sum';definemean_sales/analysismeanformat=6.2width=10'Meanof/Sales';run;结果:7如果你想让某变量的每一个值都作为一列,那就要用到across。这里要注意的是,有across选项的var,在column时后面加了一个’,’,从而将其后面的变量的数据直接放到across变量下。。procreportdata=mnthly_salesnofsheadlineheadskip;title1CrossTabReport(AcrossType);columnctyzipvar,sales;definecty/groupwidth=6'County/Name';definezip/group;definevar/acrossorder=freqdescending'-GrapeVariety-';definesales/analysissumformat=6.2width=10'Revenue';run;结果:这里,变量variety的每一个值都成为了新的列8BREAK与RBREAK,对分组后的报表汇总procreportdata=mnthly_salesnofsheadlineheadskip;title1ReportwithBreaks;columnctyzipvar,sales;definecty/groupwidth=6'County/Name';definezip/group;definevar/acrossorder=freqdescending'-GrapeVariety-';definesales/analysissumformat=6.2width=10'Revenue';breakaftercty/olskipsummarizesuppress;rbreakafter/dolskipsummarize;run;结果:这里说明一下BREAK与RBREAK后面的选项:OL汇总上方加一条线DOL汇总上方加两条线UL汇总下方加一条线DUL汇总下方加两条线summarize对每组进行汇总skip加入一空白行suppress在汇总行不显示组名9compute块,计算统计变量,这个以后将专门介绍procreportdata=mnthly_salesnofsheadlineheadskip;title1ReportwithRowSums(ComputedType);columnctyzipvar,salesrow_sum;definecty/groupwidth=6'County/Name';definezip/group;definevar/acrossorder=freqdescending'-GrapeVariety-';definesales/analysissumformat=6.2width=10'Revenue';definerow_sum/computedformat=comma10.2'Total';breakaftercty/olskipsummarizesuppress;rbreakafter/dolskipsummarize;computerow_sum;row_sum=sum(_C3_,_C4_,_C5_,_C6_,_C7_,_C8_);endcompute;run;结果:Compute块是以compute开始,endcompute为结尾,可以计算出很多复杂的数据。这里的_C*_表示第几列的变量,例如_C3_表示第三列,_C#_代表最后一行。这里的_C7_和_C8_是多余的,但不影响结果。10procreport与ODS,以后会详细介绍。这里用ODS输出report过程结果,方法很简单,就是将上面的report代码放入ods语句之间。odslistingclose;odsrtffile=‘c:\sugi30.rtf’;上面的procreport过程代码放在这里就行odsrtfclose;即:odslistingclose;odsrtffile='c:\sugi30.rtf';procreportdata=mnthly_salesnofsheadlineheadskip;title1ReportwithRowSums(ComputedType);columnctyzipvar,salesrow_sum;definecty/groupwidth=6'County/Name';definezip/group;definevar/acrossorder=freqdescending'-GrapeVariety-';definesales/analysissumformat=6.2width=10'Revenue';definerow_sum/computedformat=comma10.2'Total';breakaftercty/olskipsummarizesuppress;rbreakafter/dolskipsummarize;computerow_sum;row_sum=sum(_C3_,_C4_,_C5_,_C6_,_C7_,_C8_);endcompute;run;odsrtfclose;结果:11report设置style,让报表更炫一点。这个以后也会详细介绍odslistingclose;odsrtffile='c:\sugi30.rtf';procreportdata=mnthly_salesnofsheadlineheadskipstyle(header)={background=lightskyblueforeground=black}style(column)={background=lightcyanforeground=black};title1ReportwithRowSums(ComputedType);columnctyzipvar,salesrow_sum;definecty/groupwidth=6'County/Name';definezip/group;definevar/acrossorder=freqdescending'-GrapeVariety-';definesales/analysissumformat=6.2width=10'Revenue';definerow_sum/computedformat=comma10.2'Total';breakaftercty/olskipsummarizesuppress;rbreakafter/dolskipsummarize;computerow_sum;row_sum=sum(_C3_,_C4_,_C5_,_C6_,_C7_,_C8_);endcompute;run;odsrtfclose;结果:
本文标题:SAS-report过程介绍
链接地址:https://www.777doc.com/doc-1663425 .html