《SAS的数据定义》PPT课件.ppt_第1页
《SAS的数据定义》PPT课件.ppt_第2页
《SAS的数据定义》PPT课件.ppt_第3页
《SAS的数据定义》PPT课件.ppt_第4页
《SAS的数据定义》PPT课件.ppt_第5页
已阅读5页,还剩36页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

内容,SAS程序 data步: 数据步的类型、变量、数据定义、数据的读取与显示、数据转换语句、变量与数值标签、数据行排序、 Proc步:,Sas程序,Data步: 功能:建立数据集 方式:建立一个或多个新的SAS数据集,也包括通过执行必要的操作来建立数据集的编程语句。程序: prg2_51 数据步的类型: 1、磁盘上的数据:infile 2、作业流中的数据 3、来自其它数据集中的数据,磁盘上的数据,Data 语句; Infile 语句; Input 语句;,作业流中的数据,Data 语句; Input 语句; cards 语句; 数据行 ;,来自其它数据集中的数据,Data 语句; Set mergeupdate语句; 用于data步中的其它SAS语句,prg2_51 data prg2_51 prg2_52; set prg2_4; if sex=m then output prg2_51; else output prg2_52; run; proc print; run;,Proc步: 功能:调用SAS程序并执行,通常是进行统计分析的过程。 方式:PROC 关键词 ; PROC中的常用语句: VAR CLASS FORMAT MODEL ID LABEL FREQ OUTPUT BY ATTRIB WEIGHT,SAS变量,数值型 字符型: $,输入与输出格式,输入格式:Informat : w.d 输出格式:Format: w.d W是宽度值,d是小数位数 Input 15 style 3. 21 price 5.2; Data b; Informat birthday intervw date.; Attrib income informat=comma. Format= length=$w. label=-; Input 20 birthday intervw 50 income;,Proc format; Value sexfmt 1=male 2=female; Data all; Input name $ sex ; Format sex sexfmt.; Cards; Jane 2 bill 1 ; Proc print; Run;,data emplo; input name $ bejing date7.; format bejing worddate.; cards; zhpngli 15jan84 liuwei 03mar85 ; run; proc print; run;,SAS的数据定义,Data Input List Cards(dataline) Infile数据文件名,例,Data example; Label 血型调查; Infile f:sasexercise11.tex; Input no 1-2 sex$ 3-4 age 5-6 blood$ 7-8 curt 9-11; 数据转换命令; List; Cards; Run;,自由格式的数据定义,1、自由格式的形式一 input no sex$ age blood$ surt; cards; 1 m 41 a 368,2、自由格式的形式二 input id caseid name$ 01 001 shang minmin 1 35 18 - 01 002 li xiaohua 2 25 15 - 注意:形式二name$后面增加一个&,它把两个字符串(中间可有空格)当作一个整体字符串读取 自由格式的数据,其两边要有一个空格隔开,3、自由格式的形式三:一行多个记录 input no sex$ age blood$ surt; cards; 1 m 41 a 368 2 m 26 b 745 3 f 35 b 401 4 m 47 ab 552 5 f 37 a 478 6 f 39 0 628 7 m 28 0 549 8 m 31 b 128 9 m 43 ab 463 10 m 29 a 512,固定格式的数据定义,1、固定格式的数据定义一 Input id 1-2 caseid 3-5 n 6 sex 7 age8-9 edc 10 ocu1 11 ocu2 12 sal1 13-15 sal2 16-18 (v1-v5) (5*1.) 11001116031015012021214 11002116542218018011210 11003215531009909512210,固定格式的数据定义,2、固定格式的数据定义二 Input id 1-3 height 4-7 .1 weight 8-11 .1 sex 12 age 13-14; 00106551805145,固定格式的数据定义,3、固定格式的数据定义三 Input (v1 v2 v3 v4)(2. 2. 2. 2.); 或者改写为: Input(v1-v4)(4*2.),固定格式的数据定义,4、固定格式的数据定义四: 用n跳到n列读取 Input 7 sex 1. 3 casein 3.; 11001116031015012021214 11002116542218018011210,固定格式的数据定义,5、固定格式的数据定义五: 用+n跳n列读取 Input 3 casein 3. +2 age 8-9; 11001116031015012021214 11002116542218018011210,固定格式的数据定义,6、固定格式的数据定义六: 用#n跳到n行读取 Input 3 casein 3. #2 age 8-9; 11001116031015012021214 11002116542218018011210,数据的读取与显示,缺少值的表示法:用. List;用于显示数据格式是否对应于其栏位,以便检查数据有无错误与错位;通常用于input命令的下一行; 通过cards; 命令读取数据,数据的读取与显示,命令:Infile path: filename: 如: data newdata; infile path:filename; input var ; Run;,数据转换语句,用if进行条件转换 用delete作有条件的删除 用GO TO 作有条件的转移,用if进行条件转换,命令格式:If 条件 then 命令 else 命令 例: data older; Infile f: sasexercise3.txt; Input no 1 sex 2 age 3-4 blood 5 curt 6-8; If sex eq 1 then delete; List; Run;,If x+y=100 then list; If zy then y=x*5; Else y=x; If x1=y1|x2=y2 then list;,用delete作有条件的删除,用GO TO 作有条件的转移,Data exam; Input v1 v2 v3; If 70=v1=80 then go to ok; V2=1 Count+1 Return; Ok:sumx+v1;sumy+v2; List; Cards; 75 83 90 68 75 80 90 100 75 - Proc print; Run;,Label,命令格式:Label 变量名标签;,Format,定义数值标签 命令格式: PROC format; Value newdata 数值标签 ; Format olddata newdata.;,retain,预置变量值 命令格式:retain 变量 初值 ;,数据重新编码,Proc format; Value 变量1 low-值1新值1 值2值3 新值2 值4值5 新值3 Value 变量2 low-值1新值1 值2值3 新值2 值4值5 新值3,数据行排序,数据行排序的语法规则 PROC sort data=原数据名out=结果文件2; by 变量1 变量2 descending 变量3 -; Proc print data=文件名2; 例 proc sort data=olddata out =new; by sex age descending sal1 ocu1; 先按SEX升序排列,如果SEX值相同,则按AGE升序排列;若仍然相同,则按SAL1降序排列,当SAL1也相同,则按OCU1升序排列;,SAS程序设计技巧,PUT语句 DATA LI; Input id 1-2 se| s 4 age 5-6 height 8-10 weight 12-14 .1; Put id sex age; /*显示3个变量之值*/ Put id= weight=; /*在等号后面显示变量之值*/ Put 学生代号是 id 身高 height 体重 weight;/*结合文字显示变量值*/ List; Cards; 01 m19 173 672 02 m20 175 575 03 m19 160 540 04 m21 176 700 05 m20 158 585 ; Proc print; Run;,与put连用,可定位显示输出起始位置。 如:加入put 1 sex/height 15-17; 表示:第1列显示sex后跳到下一行的第15-17列显示height;,注释行、put语句、print格式,注释行:/*注释内容*/(或/*注释内容) Put语句的格式为:put v1 a-b n v2 10.2 新打印内容:file print;,例,程序:output1 output2,Output1程序 data score; input id job$ score ; cards; 01 chi 80 01 math 75 01 eng 95 02 chi 70 02 math 85 02 eng 92 03 chi 85 03 math 80 03 eng 94 04 chi 93 04 math 96 04 eng 88 05 chi 80 05 math 99 05 eng 86 ; proc sort; by job id score; data _null_; set score end=final; by job; title jobsocre; title3 _ ; subsco=subsco*score; totsco=totsco*score; subid+1; totid+1; put id job 5-8 score; if last.id; put /job job totalscore: 30 id= subid 40 score= subsco/; subsco=0;subid=0; if final then put totalscore: 20 id= totid 26 score totsco; proc chart; vbar job/sumvar=score;,output2程序,data score; input id job$ score ; cards; 01 chi 80 01 math 75 01 eng 95 02 chi 70 02 math 85 02 eng 92 03 chi 85 03 math 80 03 eng 94 04 chi 93 04 math 96 04 eng 88 05 chi 80 05 math 99 05 eng 86 ; proc sort;by job id score; data s; set score end=final;by job; retain sumscore chiscore engscore subscore totsco 0; title jobsocre; title3 _ ; subid+1; totid+1; if job=chi then do; sumscore=sumscore+score; chiscore=sumscore; end; if job=eng then do; sumscore=sumscore+score-chiscore/5; engscore=sumscore;end; if job=math then sumscor

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论