sas复习题.docx
- 文档编号:7552329
- 上传时间:2023-01-24
- 格式:DOCX
- 页数:26
- 大小:21.66KB
sas复习题.docx
《sas复习题.docx》由会员分享,可在线阅读,更多相关《sas复习题.docx(26页珍藏版)》请在冰豆网上搜索。
sas复习题
/*SAS复习题
optionsnodatenonumbernocenter;title;
*1--------------------------------------------------;
datafamily;
*inputrelation$first_name$birthdatedate9.;
*inputrelation$first_name$birthdatemmddyy8.;
*inputrelation$first_name$birthdate:
date9.;
inputrelation$first_name$birthdate:
mmddyy8.;
datalines;
sonFrank01/31/89
daughterJune12-25-87
brotherSamuel01/17/1951
;
procprint;
formatbirthdateyymmdd10.;
run;
*2--------------------------------------------------;
*期望获得如下输出结果:
nameageweight
Jose47210
Sue.108;
dataemployeestats;
*infiledatalinespad;
infiledatalinesdsd;
*infiledatalinesdlm=',';
*infiledatalinesmissover;
inputname$ageweight;
datalines;
Jose,47,210
Sue,,108
;
procprint;
run;
*3--------------------------------------------------;
datanumrecords;
infilecardsdlm=',';
inputagent1$agent2$agent3$;
datalines;
jones,,brownjones,spencer,brown
;
procprint;
run;
*第2个观测中变量Agent2的值是什么?
*4--------------------------------------------------;
datahouses;
input@1style$8.+1sqfeet4.+1bedrooms1.@20baths3.street$16.@40pricedollar8.;
datalines;
TWOSTORY104021SANDERSROAD$55,850
CONDO215042.5JEANSAVENUE$127,150
;
procprint;
run;
*5--------------------------------------------------;
datasasuser.sales;
setsasuser.salesdata;
profit=expenses-revenues;
run;
procprintdata=sales;*错误:
数据集Sales不存在。
;
run;
/*6--------------------------------------------------
将一个逻辑库名分配给了一个永久SAS数据库:
*正确的语句:
;
libnamemylib'd:
\mySAS';
libnamemylib'd:
/mySAS';
libnamemylib'\mySAS';
libnamemylib'mySAS';
libnamemylib'.\mylib';
libnamemylib'.';
libnamemylib'..';
libnamemylib'..\mylib';
*错误的语句:
;
libnamemySASdata'd:
\mySAS';
libnamemySASdatd:
\mySAS;
*7--------------------------------------------------;
datastaff;
hire_date='23feb1999'd;output;
hire_date='23feb2000'd;output;
hire_date='23feb2001'd;output;
run;
procprint;
run;
datastaff;
inputhire_datedate9.;
datalines;
23feb1999
23feb2000
23feb2001
;
procprint;
formathire_datemmddyy10.;
run;
datastaff;
inputhire_dateddmmyy10.;
datalines;
23/02/1999
23/02/2000
23/02/2001
;
procprint;
formathire_datemmddyy10.;
run;
datastaff;
inputhire_datemmddyy10.;
datalines;
02/23/1999
02/23/2000
02/23/2001
;
procprint;
formathire_datemmddyy10.;
run;
datastaff;
inputhire_dateyymmdd10.;
datalines;
1999/02/23
2000/02/23
2001/02/23
;
run;
procprint;
formathire_datemmddyy8.;
run;
datanewstaff;
setstaff;
wherehire_date>='23feb2000'd;
procprint;
run;
*8--------------------------------------------------
将日期值2000年1月16日显示为16/01/2002?
DATE10.
DDMMYY10.
WEEKDATE10.
DDMMYYYY10.;
*9--------------------------------------------------
在SAS任务中显示外部文件的内容;
OPTIONSNOCENTERNODATENONUMBER;
TITLE;
ODSLISTINGFILE="D:
\class.txt";
PROCPRINTDATA=SASHELP.CLASS;
RUN;
ODSLISTINGclose;
ODSLISTING;
PROCFSLISTFILEREF='d:
\class.txt';
RUN;
quit;
*10--------------------------------------------------
SAS数据集Sashelp.Prdsale包括变量Region和Salary,每个地区(Region)
中包括4个观测。
该数据集已按变量Region排序,同一个地区内又按变量
Salary降序排序,以下程序被提交:
;
dataone;
setsashelp.prdsale;
procsort;
byregiondescendingactual;
dataone;
setone;
retaintemp;
byregiondescendingactual;
iffirst.regionthendo;
temp=actual;
output;
end;
iflast.regionthendo;
range=temp-actual;
output;
end;
procprint;
run;
*每一个地区中有2个观测被写到输出数据集中;
*11--------------------------------------------------;
proccontentsdata=sashelp.class;
run;
下面显示的内容中包括了CONTENTS过程步所产生的部分输出结果。
DataSetNameSASUSER.HOUSES
Observations15
MemberTypeDATA
Variables6
EngineV9
Indexes0*数据集未未索引;
CreatedTuesday,April22,200303:
09:
25PM
ObservationLength56
LastModifiedTuesday,April22,200303:
09:
25PM
DeletedObservations0
Protection
CompressedNO
DataSetType
SortedNO*数据集未排序;
LabelResidentialhousingforsale
DataRepresentationWINDOWS_32
Encodingwlatin1Western(Windows)
*12--------------------------------------------------;
procsortdata=test;
byfnamedescendingsalary;
run;
*13--------------------------------------------------
13.以下程序被提交:
;
datanames;
*title='EDU';
title='HR';
iftitle='EDU'thenDivision='Education';
elseiftitle='HR'thenDivision='HumanResources';
elseDivision='Unknown';
procprint;
run;
*14--------------------------------------------------
创建值为1的变量d;
dataa;b='c';ifb='C'd=1;run;
dataa;b='C';ifb='C'd=1;run;
dataa;b='C';ifb='C'thend=1;run;
dataa;b='C';ifb='C';thend=1;run;
*15--------------------------------------------------
变量x的长度(length);
dataa;
lengthx$9;
x='AAAAAA';output;
x='AAAAAAA';output;
x='AAAAAAAA';output;
x='AAAAAAAAA';output;
x='AAAAAAAAAA';output;
lengthx$9;
procprint;
run;
*16--------------------------------------------------
创建值为1000的数值变量x
x=1000;
x='1000';
lengthx=8;
lengthx$8;
*17--------------------------------------------------;
datafltaten;
inputjobcode$salaryname$;
cards;
FLAT170000Bob
FLAT260000Joe
FLAT330000Ann
;
run;
datadesc;
setfltaten;
ifsalary>60000thendescription='Over60';
elsedescription='Under60';
procprint;
run;
*18--------------------------------------------------;
dataall_sales;
inputreceipts;
total+receipts;
*total0;*sumtotal;
*total=total+receipts;
*total=sum(total,receipts);
datalines;
10
23
20
15
;
procprint;
run;
*19--------------------------------------------------;
datamoney;
inputyearquantity;
total+quantity;
*total=total+quantity;
datalines;
19012
19051
19106
19251
19411
;
procprint;
run;
*20--------------------------------------------------
用函数计算平均值;
datatest;
average=mean(6,4,.,2);
procprint;
run;
*21--------------------------------------------------;
dataAreaCodes;
Phonenumber=3125551212;
Code1='('||substr(Phonenumber,1,3)||')';
Code2='('||substr(left(Phonenumber),1,3)||')';
Length1=length(Phonenumber);
Length2=length(left(Phonenumber));
procprint;
run;
*22--------------------------------------------------;
datainventory;
products=7;
*dountil(productsgt7);
dowhile(productslt7);
products+1;
end;
procprint;
run;
*23--------------------------------------------------;
datastaff;
retainsalary1-salary5(5*1);
procprint;
run;
datatest;
setstaff(keep=salary1salary2salary3);
arraysalary{3};
*arraynew_salary{3};
*arraysalary{3}salary1-salary3;
*arraynew_salary{3}salary1-salary3;
procprint;
run;
*24--------------------------------------------------;
*建立输出格式与变量之间的联系(临时联系与永久联系)
==================================================;
dataa;
inputdateyymmdd10.;
datalines;
2010/01/25
;
run;
procprint;*未定义输出格式;
run;
dataa;
date=input('2010/01/25',yymmdd10.);*****带有格式修饰符的INPUT函数;
run;
procprint;*未联系;
run;
dataa;
inputdateyymmdd10.;*****带有格式化输入的INPUT语句;
put'date='datemmddyy10.;*临时联系;
putdate=;
datalines;
2010/01/25
;
run;
dataa;
formatdateyymmdd10.;*****数据步中的FORMAT语句(永久联系);
inputdateyymmdd10.;
datalines;
2010/01/25
;
procprint;
run;
*注意:
建立了永久联系后,临时联系在需要时仍然可以建立;
procprint;
formatdatedate9.;*建立date与date9.之间的临时联系;
run;
procprint;
formatdate5.;*建立date与5.之间的临时联系;
run;
procformat;
value$sexfmt'f'='女''m'='男';*****FORMAT过程步(定义输出格式$sexfmt.);
dataa;
inputsex$@@;
datalines;
mfmf
;
run;
procprint;
formatsex$sexfmt.;*临时联系;
run;
procprint;*未联系(故打印的是天数);
run;
*建立输入格式与变量之间的联系
==============================;
dataa;
*input(date1-date2)(2*yymmdd10.);*错误(空格被误读);
inputdate1yymmdd10.+1date2yymmdd10.;*临时联系;
daysdif=date2-date1;
datalines;
2010/01/252011/01/25
;
procprint;*daysdif=18629-18287=342;
run;
dataa;
informatdate1-date2yymmdd10.;*永久联系;
inputdate1date2;
daysdif=date2-date1;
datalines;
2010/01/252011/01/25
;
procprint;*daysdif=18652-18287=365;
run;
procformat;
invalue$countryifmt'中华人民共和国'='CHN'
'美利坚合众国'='USA'
'俄罗斯联邦共和国'='RUS';
value$countryfmt'CHN'='中华人民共和国'
'USA'='美利坚合众国'
'RUS'='俄罗斯联邦共和国';
run;
dataa;
inputcountry$countryifmt.;
datalines;
CHN
USA
RUS
;
title'未使用输出格式';
procprint;
run;
title'使用了输出格式$countryfmt.';
procprint;
formatcountry$countryfmt.;
run;
title;
datab;
informatcountry$countryifmt.;
formatcountry$countryfmt.;
inputcountry$;
datalines;
CHN
USA
RUS
;
procprint;
run;
title;
*25--------------------------------------------------;
dataa;
setsasuser.houses;
procprint;
procsort;
bystyle;
procprint;
bystyle;
varprice;
run;
procfreqdata=sasuser.houses;
tablesstyleprice/nocum;
formatpricedollar10.;
labelstyle="Styleofhomes"price="Askingprice";
run;
procmeansdata=sasuser.housesnmean;
classstyle;
varprice;
formatpricedollar10.;
labelstyle="Styleofhomes"price="Askingprice";
run;
procreportdata=sasuser.housesnowdheadline;
columnstylenprice;
definestyle/group"Styleofhomes";
defineprice/meanformat=dollar8."Askingprice";
run;
*26--------------------------------------------------
procoptionsoption=PAGESIZE;
run;*PAGESIZE=36;
dataa;
doi=1to36;
output;
end;
procprint;
run;
optionsPAGESIZE=40;
procprint;
run;
dataa;
retainx1-x25(25*1000);
procprint;
run;
procoptionsoption=LINESIZE;
run;*LINESIZE=122;
optionsls=130;
procprint;
run;
procoptionsoption=PAGENO;
run;*PAGENO=1;
optionsps=36numberpageno=2;
dataa;
doi=1to100;
output;
end;
procprint;
run;
*27--------------------------------------------------;
dataa;
setsashelp.class;
labelname='同济医学院在\校学生的姓名';
procreportdata=aSPLIT='\';
run;
*28--------------------------------------------------;
odshtmlfile='d:
\newfile.html';
procprintdata=sasuser.houses;
run;
procmeansdata
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- sas 复习题
![提示](https://static.bdocx.com/images/bang_tan.gif)