您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 数据通信与网络 > Sas代码作图详解(图文并茂)
Sas代码作图详解SAS/Graph太强大了,本文主要讲一些常用且功能强大的Graph相关的过程步。1procgplot的简单例子procgplotdata=sashelp.shoes;plotReturns*Sales;run;结果:2我们也可以只画出符合条件的数据的图形。procgplotdata=sashelp.shoes;whereRegionin(UnitedStates,EasternEurope);plotReturns*Sales;run;结果:3输出的图像都是默认的黑色的小十字,因此我们不能区分来自不同地区的数据,下面的程序就是为了解决这一问题procgplotdata=sashelp.shoes;whereRegionin(UnitedStates,EasternEurope);plotReturns*Sales=Region;run;结果:这里红色的来自美国,黑色的来自东欧,当然我们也可以自己设定颜色(SAS基本颜色有:black,red,green,blue,cyan,magenta,grey,pink,orange,brown,andyellow)。4设定坐标轴和所有文字和颜色procgplotdata=sashelp.shoes;whereRegionin(UnitedStates,EasternEurope);plotReturns*Sales=Region/caxis=bluectext=redgrid;run;结果:5如果要对网格进行更精细地设置,则要用到AUTOHREF和AUTOVREF选项。AUTOHREF中,LHREF设置水平线的线类型,CHREF设置水平线的线颜色;AUTOVREF中,LVREF设置垂直线的线类型,CVREF设置垂直线的线颜色。procgplotdata=sashelp.shoes;whereRegionin(UnitedStates,EasternEurope);plotReturns*Sales=Region/autohreflhref=2chref=limeautovreflvref=5cvref=pinkcaxis=bluectext=red;run;结果:6还可以用VAXIS和HAXIS分别设置纵轴和横轴的刻度。注意:如果某个数据超过了你指定的这个刻度,那么这个数据将不会被输出,因此在用这两个选项时要非常小心。procgplotdata=sashelp.shoes;whereRegionin(UnitedStates,EasternEurope);plotReturns*Sales=Region/vaxis=0to15000by5000autohreflhref=2chref=limeautovreflvref=5cvref=pinkcaxis=bluectext=red;run;结果:7下面介绍一些有关Graph相关过程的全局(global)设置title1c=darkblueh=2.5f=swissbSAS/Graphc=darkredh=3.0f=swissbiGPLOTExample;axis1label=(c=darkorangeh=1.5f=zapfbij=rTotalReturns)offset=(0.2in)order=(0to15000by5000)value=(c=darkorangef=swissl);axis2label=(c=darkgreenh=1.5f=zapfbi)order=(0to500000by50000)value=(f=swisslc=darkgreen);symbol1c=redh=2v=#;symbol2c=blueh=3v=diamond;procgplotdata=sashelp.shoes;whereRegionin(UnitedStates,EasternEurope);plotReturns*Sales=Region/vaxis=axis1haxis=axis2autohreflhref=2chref=limeautovreflvref=5cvref=pinkcaxis=bluectext=red;run;结果:我们还可以设置这些Symbol是否用线连接起来,即INTERPOLATION=(I=)设置连接方式,以及WIDTH=(W=)设置线的宽度。symbol1c=redh=2v=#i=sm50sw=2;symbol2c=blueh=3v=diamondi=splinesw=2.5;结果略。8下面开始介绍Gchart,首先是一个简单的gchart过程步的一个简单应用。title1c=darkblueh=2.5f=swissbSAS/Graphc=darkredh=3.0f=swissbiGChartExample;procgchartdata=sashelp.shoes;vbar3dProduct/caxis=bluectext=darkblueautoreflref=2cref=lime;run;结果:9设置背景色和图形形状axis1label=(c=darkgreenh=1.5f=zapfbi)value=(f=swissbc=darkgreenh=0.75);procgchartdata=sashelp.shoes;vbar3dProduct/caxis=bluectext=darkblueautoreflref=2cref=limemaxis=axis1shape=starcframe=cyan;run;10柱状图求和显示axis1label=(c=darkgreenh=1.5f=zapfbi)value=(f=swissbc=darkgreenh=0.70);axis2label=(c=darkorangeh=1.5f=zapfbi)value=(c=darkorangef=swissl);procgchartdata=sashelp.shoes;vbar3dProduct/caxis=bluectext=darkblueautoreflref=2cref=limesumsumvar=salesmaxis=axis1raxis=axis2shape=starcframe=cyan;run;结果:11用patternid将各个柱子设为不同颜色axis1label=(c=darkgreenh=1.5f=zapfbi)value=(f=swissbc=darkgreenh=0.70);axis2label=(c=darkorangeh=1.5f=zapfbi)value=(c=darkorangef=swissl);procgchartdata=sashelp.shoes;vbar3dProduct/caxis=bluectext=darkblueautoreflref=2cref=limesumsumvar=salesmaxis=axis1raxis=axis2shape=starcframe=cyanpatternid=midpoint;run;结果:12根据分组分别显示柱状图axis1label=(c=darkgreenh=1.5f=zapfbi)value=(f=swissbc=darkgreenh=0.70);axis2label=(c=darkorangeh=1.5f=zapfbi)value=(c=darkorangef=swissl);axis3label=(c=blueh=1.5f=centbi)value=(f=swissbc=blueh=1.5);procgchartdata=sashelp.shoes;whereRegionin(UnitedStates,WesternEurope);vbar3dProduct/caxis=bluectext=darkblueautoreflref=2cref=limesumsumvar=salesmaxis=axis1raxis=axis2shape=starcframe=cyanpatternid=MIDPOINTgroup=Regiongaxis=axis3;run;结果:13设置subgroup。axis1label=(c=darkgreenh=1.5f=zapfbi)value=(f=swissbc=darkgreenh=0.70);axis2label=(c=darkorangeh=1.5f=zapfbi)value=(c=darkorangef=swissl);procgchartdata=sashelp.shoes;whereRegionin(UnitedStates,WesternEurope);vbar3dProduct/caxis=bluectext=darkblueautoreflref=2cref=limesumsumvar=salesmaxis=axis1raxis=axis2shape=starcframe=cyansubgroup=Region;run;结果:14下面设置legendaxis1label=(c=darkgreenh=1.5f=zapfbi)value=(f=swissbc=darkgreenh=0.70);axis2label=(c=darkorangeh=1.5f=zapfbi)value=(c=darkorangef=swissl);legend1frameposition=(topcenterinside)label=nonevalue=(f=swissbh=1.5t=1c=redt=2c=green);procgchartdata=sashelp.shoes;whereRegionin(UnitedStates,WesternEurope);vbar3dProduct/caxis=bluectext=darkblueautoreflref=2cref=limesumsumvar=salesmaxis=axis1raxis=axis2shape=starcframe=cyansubgroup=Regionlegend=legend1;run;结果:15Goptions太多了,就随便列一些吧:Border|Noborder--putaborderaroundtheentiregraph.Cback=--Colorofbackgroundofentiregraph.Cby=--ColorofBYline.Ctext=--Colorforalltextinthebodyofthegraph.Ctitle=--Colorforalltitles.Device=--Devicedriver.Fby=--FontforBYlines.Ftext=--Fontforalltextinthebodyofthegraph.Ftitle=--Fontforalltitles.Gsfname=--Filerefofoutputfile.Gsfmode=append|replace--dispositionofoutputfile.Hby=--HeightofBYlineHtext=--Heightofalltextinthebodyofthegraph.Htitle=--Heightofalltitles.Reset=(all|global|axis|symbol|pattern|legend|title)--Resetbacktosystemdefault.Targetdevice=--Devicedriverthatwilleventuallybeusedtoproducefinalgraph.Colors=()--Colorslist.Hsize=--Physicalsizeofgraphinhorizontalinches.Hpos=--Numberofcellsinthehorizontal.Xpixels=--Physicalsizeofgraphinhorizontalpixels
本文标题:Sas代码作图详解(图文并茂)
链接地址:https://www.777doc.com/doc-5353094 .html