《07-第七章.docx》由会员分享,可在线阅读,更多相关《07-第七章.docx(54页珍藏版)》请在优知文库上搜索。
1、第六章数据汇总与报表制作第一节运用PRlNT过程制作报表一、过程PRINT的基本语句1. 简洁形式为procprintdata=数据集名;run;数据集dst.lonpar是某航空公司95年3月第一周飞往伦敦和巴黎的航班信息,现在用过程PRINT输出它的内容。程序如076.sas所示。procprintdata=dst.Ionpar;run;ObsF1.IGHTDATEDESTMAI1.FREIGHTBOARDEDREVENUE1821110201.ON3452431S71506342213110211.ON4213582412173823821110211.ON248307215193930
2、4213110221.ON4472991831650665821110221.ON3913841861677726219110231.ON3565472111903227821110231.ON21936820318310G8213110241.ON272370187147026921911024PAR27237018715063410821110241.ON38947918818957811219110251.ON32737417715965412821110251.ON27249717415694813213110281.ON3801222292085582. NOOBS选项若去掉左侧的O
3、BS歹J,可以运用该选项。procprintdata=dst.lonparnoobs;run;程序如077.sas所示。procprintdata=dst.lonparnoobs;run;F1.IGHTDATEDESTMAI1.FREIGHTBOARDEDREVENUE821110201.ON345243167150S34219110211.ON421358241217382821110211.ON248307215193930218110221.ON447293183165066821110221.ON391384186187772219110231.ON358547211190322821
4、110231.ON219388203183108219110241.ON2723701714702821911024PAR27237016715034821110241.ON389479188163576219110251.ON32?374177159654821110251.ON272497174166948219110281.ON3801222292085583. ID语句在有些数据集中,每条记录有其自己的关键字段或标识,例如员工的工号,姓名等等,因而在不用观测的序号时,常希望将这些标识记录的变量置于输出的最左列,以便于查阅。运用ID语句就可实现这一要求。ID语句的一般形式为:ID变量1变
5、量2;ID语句的作用就是在过程PRINT的输出中,不加入OBS歹U,并将语句中指定的变量依次置于输出的最左侧的列。程序见078.sas所示。procprintdata=dst.Ionpar;iddateflight;run;DATEF1.IGHTDESTMAI1.FREIGHTBOARDEDREVENUE110208211.ON345243167150634110212191.ON421356241217382110218211.ON248307215193930110222191.ON447299183185066110228211.ON381384186167772110232191.ON
6、356547211190322110238211.ON219368203183108110242191.ON27237016714702611024219PAR272370167150634110248211.ON389479188169576110252191.ON327374177159654110258211.ON2724S7174158948110282191.ON3801222292065584. VAR语句为了限制变量是否输出以及它们的次序,可运用VAR语句,它的形式如下:VAR变量1变量2;VAR语句一方面指明要输出的变量,另一方面也表明它们出现的次序。程序见079.sas所示。
7、procprintdata=dst.lonpar;vardateflightdestboardedrevenue;run;ObsDATEF1.IGHTDESTBOARDEDREVENUE1110208211.ON1871506342110212191.ON2412173823110218211.ON2151939304110222191.ON1831650665110228211.ON18G187772110232191.ON2111903227110238211.ON203183108110242191.ON18714702911024219PAR18715063410110248211.O
8、N18816357811110252191.ON17715965412110258211.ON17415834813110262191.ON2292085585. WHERE语句一般形式WHERE表达式;作用:只输出访表达式成立的观测。程序见080.sas所示。procprintdata=dst.lonar;vardateflightdestboardedrevenue;whereflight-219,;run;ObsDATEF1.IGHTDESTBOARDEDREVENUE2110212191.ON2412173824110222191.ON1831850668110232191.ON211
9、1903228110242191.ON17147026311024219PAR1715063411110252191.ON17715965413110262191.ON229206558为了实现对观测的选择,也可运用PRINT的如下选项FIRSTC)BS=和OBS=;留意,该选项必需放在括号中,但是NOOBS选项绝不能带括号!程序如080a.sas所示。procprintdata=dst.bclass(firstobs=Iobs=5);run;结果见下。DbsNAME123451.AWRENCE1717278.1JEFFERY1416951.3EDWARD1418750.8PHI1.1.IP1
10、618758.1KIRK17167SO.8AGEHEIGHTSEXWEIGHT6. SUM语句一般形式SUM变量1变量2;作用:对输出的数值变量计算其总和。程序见081.sas所示。procprintdata=dst.lonpar;vardateflightdestboardedrevenue;sumboardedrevenue;run;结果如下:ObsDATEF1.IGHTDESTBOARDEDREVENUE1110208211.ON1S71508342110212191.ON2412173823110218211.ON2151938304110222191.ON18316506651102
11、28211.ON1861677726110232191.ON2111903227110238211.ON2031831088110242191.ON187147026911024219PAR18715083410110248211.ON18816957811110252191.ON17715965412110258211.ON17415694813110262191.ON229208558250822586087. BY语句BY语句即分组小计。在较大的数据集的报表中,不仅要对某些变量计算它的总和,还常须要分组计算它的小计。例如对数据集dst.lonpar,可以按航班计算总乘客人数,也可按日期计
12、算总乘客人数。要在过程PRlNT中实现这一点只要在过程步中加入BY语句,它的形式为BY变量1变量2;加入BY语句,SUM语句的求和功能就是按BY变量的值交叉分组后,计算每个组内指定变量的合计,同时也计算总和。和其它过程一样,过程PRINT中运用了BY语句,就要求读入的数据集必需是按BY变量排序的。若原数据集尚未按BY变量排序,可先用过程SoRT对数据集进行排序。程序如082.sas;procsortdata=dst.airlineout=sorted;byflight;procprintdata=sorted;varflightdatedestboarded;sumboarded;byflight;run;另一个程序如083.sas;procsortdata=dst.bclassout=sorted;bysexage;procprintdata=sorted;varsexageh