1、sas复习题/* SAS复习题options nodate nonumber nocenter; title;* 1 -;data family;*input relation $ first_name $ birthdate date9.;*input relation $ first_name $ birthdate mmddyy8.;*input relation $ first_name $ birthdate : date9.;input relation $ first_name $ birthdate : mmddyy8.;datalines;son Frank 01/31/89
2、daughter June 12-25-87brother Samuel 01/17/1951;proc print;format birthdate yymmdd10.;run;* 2 -;*期望获得如下输出结果:name age weightJose 47 210Sue . 108;data employeestats;*infile datalines pad;infile datalines dsd;*infile datalines dlm=,;*infile datalines missover;input name $ age weight;datalines;Jose,47,2
3、10Sue, ,108;proc print;run;* 3 -;data numrecords;infile cards dlm=,;input agent1 $ agent2 $ agent3 $;datalines;jones, ,brownjones,spencer,brown;proc print;run;*第2个观测中变量Agent2的值是什么?* 4 -;data houses;input 1 style $8. +1 sqfeet 4. +1 bedrooms 1. 20 baths 3. street $16. 40 price dollar8.;datalines;TWOS
4、TORY 1040 2 1 SANDERS ROAD $55,850CONDO 2150 4 2.5 JEANS AVENUE $127,150;proc print;run;* 5 -;data sasuser.sales;set sasuser.salesdata;profit=expenses-revenues;run;proc print data=sales;*错误:数据集Sales不存在。;run;/* 6 -将一个逻辑库名分配给了一个永久SAS数据库:*正确的语句:;libname mylib d:mySAS;libname mylib d:/mySAS;libname myli
5、b mySAS;libname mylib mySAS;libname mylib .mylib;libname mylib .;libname mylib .;libname mylib .mylib;*错误的语句:;libname mySASdata d:mySAS;libname mySASdat d:mySAS;* 7 -;data staff;hire_date=23feb1999d;output;hire_date=23feb2000d;output;hire_date=23feb2001d;output;run;proc print;run;data staff;input hi
6、re_date date9.;datalines;23feb199923feb200023feb2001;proc print;format hire_date mmddyy10.;run;data staff;input hire_date ddmmyy10.;datalines;23/02/199923/02/200023/02/2001;proc print;format hire_date mmddyy10.;run;data staff;input hire_date mmddyy10.;datalines;02/23/199902/23/200002/23/2001;proc pr
7、int;format hire_date mmddyy10.;run;data staff;input hire_date yymmdd10.;datalines;1999/02/232000/02/232001/02/23;run;proc print;format hire_date mmddyy8.;run;data newstaff;set staff;where hire_date=23feb2000d;proc print;run;* 8 -将日期值2000年1月16日显示为16/01/2002?DATE10.DDMMYY10.WEEKDATE10.DDMMYYYY10.;* 9
8、-在SAS任务中显示外部文件的内容;OPTIONS NOCENTER NODATE NONUMBER;TITLE;ODS LISTING FILE=D:class.txt;PROC PRINT DATA= SASHELP.CLASS;RUN;ODS LISTING close;ODS LISTING;PROC FSLIST FILEREF=d:class.txt;RUN;quit;* 10 -SAS数据集Sashelp.Prdsale包括变量Region和Salary,每个地区(Region)中包括4个观测。该数据集已按变量Region排序,同一个地区内又按变量Salary降序排序,以下程序被
9、提交:;data one;set sashelp.prdsale;proc sort;by region descending actual;data one;set one;retain temp;by region descending actual;if first.region then do;temp=actual;output;end;if last.region then do;range=temp-actual;output;end;proc print;run;*每一个地区中有2个观测被写到输出数据集中;* 11 -;proc contents data=sashelp.cl
10、ass;run;下面显示的内容中包括了CONTENTS过程步所产生的部分输出结果。Data Set Name SASUSER.HOUSES Observations 15Member Type DATA Variables 6Engine V9Indexes 0 *数据集未未索引;Created Tuesday, April 22,2003 03:09:25 PMObservation Length 56Last Modified Tuesday, April 22,2003 03:09:25 PMDeleted Observations 0ProtectionCompressed NODat
11、a Set Type Sorted NO *数据集未排序;Label Residential housing for saleData Representation WINDOWS_32Encoding wlatin1 Western (Windows)* 12 -;proc sort data=test;by fname descending salary;run;* 13 -13. 以下程序被提交:;data names;*title=EDU;title=HR;if title=EDU then Division=Education;else if title=HR then Divisi
12、on=Human Resources;else Division=Unknown;proc print;run;* 14 -创建值为1的变量d;data a;b=c;if b=C d=1;run;data a;b=C;if b=C d=1;run;data a;b=C;if b=C then d=1;run;data a;b=C;if b=C;then d=1;run;* 15 -变量x的长度(length);data a;length x $ 9;x=AAAAAA;output;x=AAAAAAA; output;x=AAAAAAAA; output;x=AAAAAAAAA; output;
13、x=AAAAAAAAAA; output;length x $ 9;proc print;run;* 16 -创建值为1000的数值变量xx=1000;x=1000;length x=8;length x $ 8;* 17 -;data fltaten;input jobcode $ salary name $;cards;FLAT1 70000 BobFLAT2 60000 JoeFLAT3 30000 Ann;run;data desc;set fltaten;if salary60000 then description=Over 60;else description=Under 60
14、;proc print;run;* 18 -;data all_sales;input receipts;total+receipts;*total 0;*sum total;*total=total+receipts;*total=sum(total,receipts);datalines;10232015;proc print;run;* 19 -;data money;input year quantity;total+quantity;*total=total+quantity;datalines;1901 21905 11910 61925 11941 1;proc print;ru
15、n;* 20 -用函数计算平均值;data test;average=mean(6,4,.,2);proc print;run;* 21 -;data AreaCodes;Phonenumber=3125551212;Code1=(|substr(Phonenumber,1,3)|);Code2=(|substr(left(Phonenumber),1,3)|);Length1=length(Phonenumber);Length2=length(left(Phonenumber);proc print;run;* 22 -;data inventory;products=7;*do unti
16、l (products gt 7);do while (products lt 7);products+1;end;proc print;run;* 23 -;data staff;retain salary1-salary5 (5*1);proc print;run;data test;set staff (keep=salary1 salary2 salary3);array salary3;*array new_salary3;*array salary3 salary1-salary3;*array new_salary3 salary1-salary3;proc print;run;
17、* 24 -;* 建立输出格式与变量之间的联系(临时联系与永久联系)=;data a;input date yymmdd10.;datalines;2010/01/25;run;proc print; *未定义输出格式;run;data a;date=input(2010/01/25,yymmdd10.); *带有格式修饰符的INPUT函数;run;proc print; *未联系;run;data a;input date yymmdd10.; *带有格式化输入的INPUT语句;put date= date mmddyy10.; *临时联系;put date=;datalines;2010/
18、01/25;run;data a;format date yymmdd10.; *数据步中的FORMAT语句(永久联系);input date yymmdd10.;datalines;2010/01/25;proc print;run;*注意:建立了永久联系后,临时联系在需要时仍然可以建立;proc print;format date date9.; *建立date与date9.之间的临时联系;run;proc print;format date 5.; *建立date与5.之间的临时联系;run;proc format;value $sexfmt f=女 m=男; *FORMAT过程步(定义
19、输出格式$sexfmt.);data a;input sex $ ;datalines;m f m f;run;proc print;format sex $sexfmt.; *临时联系;run;proc print; *未联系(故打印的是天数);run;* 建立输入格式与变量之间的联系=;data a;*input (date1-date2) (2*yymmdd10.); *错误(空格被误读);input date1 yymmdd10. +1 date2 yymmdd10.; *临时联系;daysdif=date2-date1;datalines;2010/01/25 2011/01/25;
20、proc print; *daysdif = 18629 - 18287 = 342;run;data a;informat date1-date2 yymmdd10.; *永久联系;input date1 date2;daysdif=date2-date1;datalines;2010/01/25 2011/01/25;proc print; *daysdif = 18652 - 18287 = 365;run;proc format;invalue $countryifmt 中华人民共和国=CHN 美利坚合众国=USA 俄罗斯联邦共和国=RUS;value $countryfmt CHN=
21、中华人民共和国 USA=美利坚合众国 RUS=俄罗斯联邦共和国;run;data a;input country $countryifmt.;datalines;CHNUSARUS;title 未使用输出格式;proc print;run;title 使用了输出格式$countryfmt.;proc print;format country $countryfmt.;run;title;data b;informat country $countryifmt.;format country $countryfmt.;input country $;datalines;CHNUSARUS;pro
22、c print;run;title;* 25 -;data a;set sasuser.houses;proc print;proc sort;by style;proc print;by style;var price;run;proc freq data=sasuser.houses;tables style price /nocum;format price dollar10.;label style=Style of homes price=Asking price;run;proc means data=sasuser.houses n mean;class style;var pr
23、ice;format price dollar10.;label style=Style of homes price=Asking price;run;proc report data=sasuser.houses nowd headline;column style n price;define style / group Style of homes;define price / mean format=dollar8. Asking price;run;* 26 -proc options option=PAGESIZE;run; *PAGESIZE=36;data a;do i=1
24、to 36;output;end;proc print;run;options PAGESIZE=40;proc print;run;data a;retain x1-x25 (25*1000);proc print;run;proc options option=LINESIZE;run; *LINESIZE=122;options ls=130;proc print;run;proc options option=PAGENO;run; *PAGENO=1;options ps=36 number pageno=2;data a;do i=1 to 100;output;end;proc print;run;* 27 -;data a;set sashelp.class;label name=同济医学院在校学生的姓名;proc report data=a SPLIT=;run;* 28 -;ods html file=d:newfile.html;proc print data=sasuser.houses;run;proc means data
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1