SAS Data Step 1b Reading Different Types of Data[最新]_第1页
SAS Data Step 1b Reading Different Types of Data[最新]_第2页
SAS Data Step 1b Reading Different Types of Data[最新]_第3页
SAS Data Step 1b Reading Different Types of Data[最新]_第4页
SAS Data Step 1b Reading Different Types of Data[最新]_第5页
已阅读5页,还剩44页未读 继续免费阅读

下载本文档

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

文档简介

1、,Reading,Different,Types,of,Data, Fudan_R_Module_020810 1 1 1 Content Start,with,creating,a,SAS,Data,Set Using,list,input,to,read,delimited,raw,data,fil es Other,Input,Styles Input,raw,data,in,SAS Reading,Excel,Spreadsheets Variable,Attributes Fudan_R_Module_020810 2 2 data,SAS-data-set-name; ,infil

2、e,raw-data-filename; ,input,input-specifications; run; data,SAS-data-set-name; ,infile,raw-data-filename; ,input,input-specifications; data,SAS-data-set-name; ,infile,raw-data-filename; data,demog; ,infile,C:ABCraw_data.txt; ,input,subjid,$ ,smoke,$,race, ,$,age; run; Creating,a,SAS,Data,Set 1 1 2 1

3、-5-0-5-0- 1001 EXSMOKER ASIAN 30 1002 NONSMOKER BLACK 54 1003 EXSMOKER BLACK 45 Raw Data File DATA,Step SAS Data Set In,order,to,create,a,SAS,data,set,from,a,raw, ,data,file,you,must start,a,DATA,step,and,name,the,SAS,data,set, ,being,created,(DATA,statement) identify,the,location,of,the,raw,data,fi

4、le,to,read, ,(INFILE,statement) describe,how,to,read,the,data,fields,from,the,ra w,data,file,(INPUT,statement). . Fudan_R_Module_020810 3 3 DATA,Statement Starts,the,DATA,step,and,names,the,SAS,data, ,set,being,created. Syntax , DATA,data-set-name-1, .,.,.data-set-name-n, Fudan_R_Module_020810 4 4 H

5、ow,to,create, temporary,dataset permanent,dataset, one,or,more,output,data,sets ,Exampl e1 Fudan_R_Module_020810 5 5 .,Not,Creating,a,Data,Set, , , Note:,Usually,the,DATA,statement,specifies,at,lea st,one,data,set,name,that, ,SAS,uses,to,cre ate,an,output,data,set.,However,when,the,purp ose,of,a ,DA

6、TA,step,is,to, ,write,a,report,or,to,write,data,to,an,externa l,file,you,may, ,not,want,to,crea te,an,output,data,set.,Using,the,keyword,_NUL L_,as,the, ,data,set,name,c auses,SAS,to,execute,the,DATA,step,without,w riting ,observations,to,a, ,data,set., LOG,Info. data,_NULL_; ,input,subjid,$,sex$,ag

7、e; ,put,subjid,sex,age; ,cards; ,1001,M,35 ,1002,M,28 ,1003,F,30 ,1004,M,29 ,; run; LOG,Info. Fudan_R_Module_020810 6 6 6 Content Start,with,creating,a,SAS,Data,Set Using,list,input,to,read,delimited,raw,data,fil es Other,Input,Styles Input,raw,data,in,SAS Reading,Excel,Spreadsheets Variable,Attribu

8、tes Fudan_R_Module_020810 7 7 Data,Type Two,common,data,types: Fixed,Fields Delimited,Data Fudan_R_Module_020810 8 8 Fixed,Fields In,fixed,columns. Arranged,regularly. 1001 EXSMOKER ASIAN 30 1002 NONSMOKER BLACK 54 1003 EXSMOKER BLACK 45 1004 EXSMOKER WHITE 55 1005 NONSMOKER WHITE 51 1006 NONSMOKER

9、BLACK 38 -+-10-+-20- Fudan_R_Module_020810 9 9 Delimited,Data Not,in,fixed,columns. Separated,by,the,same,delimiters. Delimiters ,Blanks,(default) ,Commas ,Tab,characters 1001 EXSMOKER ASIAN 30 1002 NONSMOKER BLACK 54 1003 EXSMOKER BLACK 45 1004 EXSMOKER WHITE 55 1005 NONSMOKER WHITE 51 1006 NONSMOK

10、ER BLACK 38 -+-10-+-20- Fudan_R_Module_020810 10 1 0 Input,Style Four,basic,Input,Styles List,Input Column,Input Formatted,Input Named,Input. Choose,the,Input,style,depending,on,the,layout, of,data,values,in,the,records. Fudan_R_Module_020810 11 1 1 Using,list,input,to,read,delimited,raw, ,data,file

11、s Syntax variable,:,names,a,variable,that,is,assigned, ,input, values. , $,:indicates,that,the,variable,has,character ,values,rather,than,numeric,values. INPUT,variable,;, Fudan_R_Module_020810 12 1 2 Example data,demog; ,infile,C:ABCraw_data.txt; ,input,subjid,$ ,smoke,$,race, ,$,age; run; SAS,Data

12、,Set Data,Step Fudan_R_Module_020810 13 1 3 ,holds,the,input,record,for,the,executio n,of,the,next,INPUT,statement,within,the,same, ,iteration,of,the,DATA,step., ,Tip:,The,trailing,prevents,the,next,INP UT,statement,from,automatically,releasing,the,curren t,input,record,and,reading,the,next,record,i

13、nto, ,the,input,buffer.,It,is,useful,when,you,need,t o,read,from,a,record,multiple,times. ,holds,the,input,record,for,the,execution,of,the,next,INPUT,statement,ac ross,iterations,of,the,DATA,step., ,Tip:,The,double,trailing,is,useful,when,each,input,line,contains,values,for, ,several,observations. ,

14、Example2 Fudan_R_Module_020810 14 1 4 PDV Looking,Behind,the,Scenes data,demog; ,infile,C:ABCraw_data.txt; ,input,subjid,$ ,smoke,$,race,$,age; run; 1001,EXSMOKER,ASIAN,30 1002,NONSMOKER,BLACK,54 1003,EXSMOKER,BLACK,45 1004,EXSMOKER,WHITE,55 1005,NONSMOKER,WHITE,51 1006,NONSMOKER,BLACK,38 Raw,Data,F

15、ile Input Buffer Compile SUBJID $ 8 SMOKE $ 8 RACE $ 8 AGE N 8 . The,default,length,of,va riables,is,8,bytes. Fudan_R_Module_020810 15 1 5 data,demog; ,infile,C:ABCraw_data.txt; ,input,subjid,$ ,smoke,$,race,$,age; run; 1001,EXSMOKER,ASIAN,30 1002,NONSMOKER,BLACK,54 1003,EXSMOKER,BLACK,45 1004,EXSMO

16、KER,WHITE,55 1005,NONSMOKER,WHITE,51 1006,NONSMOKER,BLACK,38 Raw,Data,File Input Buffer SUBJID $ 8 SMOKE $ 8 RACE $ 8 AGE N 8 . Execute . PDV Fudan_R_Module_020810 16 1 6 data,demog; ,infile,C:ABCraw_data.txt; ,input,subjid,$ ,smoke,$,race,$,age; run; 1001,EXSMOKER,ASIAN,30 1002,NONSMOKER,BLACK,54 1

17、003,EXSMOKER,BLACK,45 1004,EXSMOKER,WHITE,55 1005,NONSMOKER,WHITE,51 1006,NONSMOKER,BLACK,38 Raw,Data,File Input Buffer SUBJID $ 8 PDV SMOKE $ 8 RACE $ 8 AGE N 8 . 1,0,0,1,E,X,S,M,O,K,E,R,A,S,I,A,N,3,0 1001 EXSMOKER ASIAN30 Fudan_R_Module_020810 17 1 7 data,demog; ,infile,C:ABCraw_data.txt; ,input,s

18、ubjid,$ ,smoke,$,race,$,age; run; 1001,EXSMOKER,ASIAN,30 1002,NONSMOKER,BLACK,54 1003,EXSMOKER,BLACK,45 1004,EXSMOKER,WHITE,55 1005,NONSMOKER,WHITE,51 1006,NONSMOKER,BLACK,38 Raw,Data,File SUBJID $ 8 PDV SMOKE $ 8 RACE $ 8 AGE N 8 . 1001 EXSMOKER ASIAN30 Implicit,output Write out observation to Demo

19、g. Input Buffer 1,0,0,1,E,X,S,M,O,K,E,R,A,S,I,A,N,3,0 Fudan_R_Module_020810 18 1 8 data,demog; ,infile,C:ABCraw_data.txt; ,input,subjid,$ ,smoke,$,race,$,age; run; 1001,EXSMOKER,ASIAN,30 1002,NONSMOKER,BLACK,54 1003,EXSMOKER,BLACK,45 1004,EXSMOKER,WHITE,55 1005,NONSMOKER,WHITE,51 1006,NONSMOKER,BLAC

20、K,38 Raw,Data,File SUBJID $ 8 PDV SMOKE $ 8 RACE $ 8 AGE N 8 . 1001 EXSMOKER ASIAN30 Implicit,return Input Buffer 1,0,0,1,E,X,S,M,O,K,E,R,A,S,I,A,N,3,0 Fudan_R_Module_020810 19 1 9 data,demog; ,infile,C:ABCraw_data.txt; ,input,subjid,$ ,smoke,$,race,$,age; run; 1001,EXSMOKER,ASIAN,30 1002,NONSMOKER,

21、BLACK,54 1003,EXSMOKER,BLACK,45 1004,EXSMOKER,WHITE,55 1005,NONSMOKER,WHITE,51 1006,NONSMOKER,BLACK,38 Raw,Data,File SUBJID $ 8 SMOKE $ 8 RACE $ 8 AGE N 8 . PDV . Input Buffer 1,0,0,1,E,X,S,M,O,K,E,R,A,S,I,A,N,3,0 Fudan_R_Module_020810 20 2 0 data,demog; ,infile,C:ABCraw_data.txt; ,input,subjid,$ ,s

22、moke,$,race,$,age; run; 1001,EXSMOKER,ASIAN,30 1002,NONSMOKER,BLACK,54 1003,EXSMOKER,BLACK,45 1004,EXSMOKER,WHITE,55 1005,NONSMOKER,WHITE,51 1006,NONSMOKER,BLACK,38 Raw,Data,File SUBJID $ 8 SMOKE $ 8 RACE $ 8 AGE N 8 . PDV 1002 NONSMOKE BLACK54 Input Buffer 1,0,0,2,N,O,N,S,M,O,K,E,R,B,L,A,C,K,5,4 Fu

23、dan_R_Module_020810 21 2 1 data,demog; ,infile,C:ABCraw_data.txt; ,input,subjid,$ ,smoke,$,race,$,age; run; 1001,EXSMOKER,ASIAN,30 1002,NONSMOKER,BLACK,54 1003,EXSMOKER,BLACK,45 1004,EXSMOKER,WHITE,55 1005,NONSMOKER,WHITE,51 1006,NONSMOKER,BLACK,38 Raw,Data,File SUBJID $ 8 SMOKE $ 8 RACE $ 8 AGE N 8

24、 . PDV 1002 NONSMOKE BLACK54 Implicit,output Write out observation to Demog. Input Buffer 1,0,0,2,N,O,N,S,M,O,K,E,R,B,L,A,C,K,5,4 Fudan_R_Module_020810 22 2 2 data,demog; ,infile,C:ABCraw_data.txt; ,input,subjid,$ ,smoke,$,race,$,age; run; 1001,EXSMOKER,ASIAN,30 1002,NONSMOKER,BLACK,54 1003,EXSMOKER

25、,BLACK,45 1004,EXSMOKER,WHITE,55 1005,NONSMOKER,WHITE,51 1006,NONSMOKER,BLACK,38 Raw,Data,File SUBJID $ 8 SMOKE $ 8 RACE $ 8 AGE N 8 . PDV 1002 NONSMOKE BLACK54 Implicit,return Input Buffer 1,0,0,2,N,O,N,S,M,O,K,E,R,B,L,A,C,K,5,4 Fudan_R_Module_020810 23 2 3 data,demog; ,infile,C:ABCraw_data.txt; ,i

26、nput,subjid,$ ,smoke,$,race,$,age; run; 1001,EXSMOKER,ASIAN,30 1002,NONSMOKER,BLACK,54 1003,EXSMOKER,BLACK,45 1004,EXSMOKER,WHITE,55 1005,NONSMOKER,WHITE,51 1006,NONSMOKER,BLACK,38 Raw,Data,File SUBJID $ 8 SMOKE $ 8 RACE $ 8 AGE N 8 . PDV 1002 NONSMOKE BLACK54 Input Buffer 1,0,0,2,N,O,N,S,M,O,K,E,R,

27、B,L,A,C,K,5,4 Continue,processing,until,end,of,the,raw,data,file. Fudan_R_Module_020810 24 2 4 PROC,PRINT,Output proc,print,data=demog,noobs; run; subjid,smoke,race,ag e ,1001,EXSMOKER,ASIAN,30 ,1002,NONSMOKE,BLACK,54 ,1003,EXSMOKER,BLACK,45 ,1004,EXSMOKER,WHITE,55 ,1005,NONSMOKE,WHITE,51 ,1006,NONS

28、MOKE,BLACK,38 UNEXPECTED,VALUE Fudan_R_Module_020810 25 2 5 Length,Statement Using,length,statement,to,define,the,length,of,c haracter,variables, Syntax LENGTH,variable,length,.; Fudan_R_Module_020810 26 2 6 Length,Statement Example PROC,PRINT,Output ,subjid,smoke,race, ,age ,1001,EXSMOKER,ASIAN,30

29、,1002,NONSMOKER,BLACK,54 ,1003,EXSMOKER,BLACK,45 ,1004,EXSMOKER,WHITE,55 ,1005,NONSMOKER,WHITE,51 ,1006,NONSMOKER,BLACK,38 data,demog; ,length,subjid,$5,smoke,$10,race,$10; ,infile,C:ABCraw_data.txt; ,input,subjid,$ ,smoke,$,race,$,age; run; Fudan_R_Module_020810 27 2 7 Infile,Statement Identifies,a

30、n,external,file,to,read,with,an,INPUT ,statement, Syntax , , INFILE,file-specification,; Fudan_R_Module_020810 28 2 8 Infile,Statement,Cont. file-specification, ,external-file,: ,specifies,the,physical, ,name,of,an,external,file , ,fileref,: ,specifies,the,fileref, ,of,an,external,file. ,fileref(fil

31、e), , ,CARDS,|,CARDS4|Datalines|Datalines4 data,demog; ,infile,C:ABCraw_data.txt; ,input,subjid,$; run; filename,rawdata,C:ABCraw_data.txt; data,demog; ,infile,rawdata; ,input,subjid,$; run; Fudan_R_Module_020810 29 2 9 Infile,Statement,Cont. Options, ,DELIMITER=,quoted,string, ,specifies,an,alterna

32、te,delimiter,(other,th an,a,blank),to,be,used,for,LIST,input ,quoted,string,:specifies,one,or,more,ch aracters,to,read,as,delimiters., data,demog; ,length,subjid,$5,dose,$8; ,infile,C:ABCraw_data2.txt,delimiter=,; ,input,subjid,$, ,dosedate:,date9., ,dose,$; run; 1001,01JAN2010,10MG 1002,05FEB2010,1

33、0MG, 1003,19DEC2009,10MG 1004,25JAN2010,10MG 1005,31DEC2009,10MG 1006,15JAN2010,10MG Raw,data,(raw_data2.txt) Data,Step Fudan_R_Module_020810 30 3 0 Infile,Statement,Cont. ,DSD, ,When,you,specify,DSD,SAS,treats,two, consecutive,delimiters,as,a,missing,value ,Missover ,prevents,an,INPUT,statement,fro

34、m,reading, a,new,input ,data,record,if,it,does,not,find,values, ,in,the,current,input,line,for,all,the,variables,i n,the,statement.,When,an,INPUT, ,statement,reaches,the,end,of,the,curren t,input,data,record, ,variables,without,any,values,assigned,are, ,set,to,missing,. , ,Exa mple3 Fudan_R_Module_0

35、20810 31 3 1 Problem Option Non-blank delimiters DLM=delimiter(s) Missing data at end of row MISSOVER Missing data represented by consecutive delimiters and/or Embedded delimiters where values are surrounded by double quotes DSD INFILE,Statement,Options These,options,can,be,used,separately,or,togeth

36、er,in,the,INFILE,statement., Fudan_R_Module_020810 32 3 2 Modified,list,input Syntax INPUT,variable,:,informat; Examples,of,informats,are COMMAw. reads,numeric,data,($4,242),and,strips,out,selected,nonnumeric,characte rs,such,as,dollar,signs,and,commas. MMDDYYw.reads,dates,in,the,form,12/31/2012. DA

37、TEw.reads,dates,in,the,form,29Feb2000. TIMEw.,reads,dates,in,the,form,11:30. Fudan_R_Module_020810 33 3 3 Example 1001,10/30/2009,10:00,A 1002,11/11/2009,10:01,B 1003,10/25/2009,10:00,B 1004,12/17/2009,10:03,B 1005,12/01/2009,10:05,A 1006,10/06/2009,10:01,A Raw,Data,(raw_data4.txt) data,demog; ,infi

38、le,C:ABCraw_data4.txt,; ,input,subjid,$, ,dosedate:,MMDDYY10., ,dosetime:,time5. ,drugname,$; run; Data,Step Fudan_R_Module_020810 34 3 4 3 4 Content Start,with,creating,a,SAS,Data,Set Using,list,input,to,read,delimited,raw,data,fil es Other,Input,Styles Input,raw,data,in,SAS Reading,Excel,Spreadshe

39、ets Variable,Attributes Fudan_R_Module_020810 35 3 5 Using,Column,Input,to,read,fixed,raw, ,data,files Column,input,is,appropriate,for,reading data,in,fixed,columns Syntax INPUT,variable,start-column,; start- column,:specifies,the,first,column,of,the,input,record,that,contains,the,v alue,to,read., ,

40、-,end- column,:specifies,the,last,column,of,the,input,record,that,contains,the,va lue,to,read. Fudan_R_Module_020810 36 3 6 Example 1001 EXSMOKER ASIAN 30 1002 NONSMOKER BLACK 54 1003 EXSMOKER BLACK 45 1004 EXSMOKER WHITE 55 1005 NONSMOKER WHITE 51 1006 NONSMOKER BLACK 38 -+-10-+-20- Raw,Data,(raw_d

41、ata2.txt) data,demog; ,infile,C:ABCraw_data.txt; ,input,subjid,$,1-4,smoke,$,5-14 ,race,$15-20,age,21-23; run; Data,Step Fudan_R_Module_020810 37 3 7 Syntax,for,the,other,input,style, Formatted,input Named,input , ,INPUT,variable,informat.,; ,INPUT,variable=,; Fudan_R_Module_020810 38 3 8 3 8 Conten

42、t Start,with,creating,a,SAS,Data,Set Using,list,input,to,read,delimited,raw,data,fil es Other,Input,Styles Input,raw,data,in,SAS Reading,Excel,Spreadsheets Variable,Attributes Fudan_R_Module_020810 39 3 9 DATALINES,statement The,last,statement,in,the,DATA,step Immediately,precedes,the,first,data,lin

43、e., Use,a,null,statement,(a,single,semicolon),to,ind icate,the,end,of,the,input,data. Syntax, ,Datalines; Fudan_R_Module_020810 40 4 0 Example data,demog; ,infile,datalines,delimiter=,;, ,input,subjid,$,smoke,$,race,$,age; ,datalines; 1001,EXSMOKER,ASIAN,30 1002,NONSMOKER,BLACK,54 1003,EXSMOKER,BLAC

44、K,45 1004,EXSMOKER,WHITE,55 1005,NONSMOKER,WHITE,51 1006,NONSMOKER,BLACK,38 ; run; With,the,INFILE,statement,to,re ad,in- stream,data,lines,you,can,use, ,list,input,to,read,data,values, ,that,are,delimited,by,commas,i nstead,of,blanks., Fudan_R_Module_020810 41 4 1 CDARS,statement Is,same,to,the,Dat

45、alines,statement. Syntax CARDS; Fudan_R_Module_020810 42 4 2 CARDS4/,DATALINES4,statement Use,the,CDARS/DATALINES4,statement,when,data, contain,semicolons., Following,the,data,lines,four,consecutive,semicolon s,should,be,located,in,columns,1,through,4., Example data,demog; ,input,subjid,$,smoke,$,ra

46、ce,$,age; ,datalines4; 1001,EXSMOKER;,ASIAN,30 1002,NONSMOKER;,BLACK,54 1003,EXSMOKER;,BLACK,45 1004,EXSMOKER;,WHITE,55 1005,NONSMOKER;,WHITE,51 1006,NONSMOKER;,BLACK,38 ; run; Fudan_R_Module_020810 43 4 3 4 3 Content Start,with,creating,a,SAS,Data,Set Using,list,input,to,read,delimited,raw,data,fil

47、 es Other,Input,Styles Input,raw,data,in,SAS Reading,Excel,Spreadsheets Exercise Fudan_R_Module_020810 44 4 4 Create,a,SAS,data,set,from,an,Excel, ,spreadsheet,using,PROC,IMPORT Syntax Example PROC,IMPORT,OUT=,SAS-data-set, ,DATAFILE=,external-file-name, ,DBMS=EXCEL2000,; ,GETNAMES=YES; RUN; PROC,IM

48、PORT,OUT=,random, ,DATAFILE=,c:ABCtest.xls, ,DBMS=EXCEL2000,REPLACE; ,RANGE=sheet1.$;, ,GETNAMES=YES; RUN; Fudan_R_Module_020810 45 4 5 4 5 Content Start,with,creating,a,SAS,Data,Set Using,list,input,to,read,delimited,raw,data,fil es Other,Input,Styles Input,raw,data,in,SAS Reading,Excel,Spreadsheets ,Exercise

温馨提示

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

评论

0/150

提交评论