岳朝龙《SAS与现代经济统计分析》例题程序
第二章例2.1程序如下:data year2000 year2001;input year jsjname$ jsjquan jsjprice jsjsale dyjname$ dyjquan dyjprice dyjsale;if year=2000 then output year2000;else output year2001;cards;2000 jsj 1000 4500 4500000 dyj 800 2000 16000002001 jsj 1200 4000 4800000 dyj 1000 1500 1500000;若想把计算机和打印机的销售资料分开,程序如下:data jsjdyj jsj(keep=year jsjname jsjquan jsjprice jsjsale) dyj(drop=jsjname jsjquan jsjprice jsjsale);input year jsjname$ jsjquan jsjprice jsjsale dyjname$ dyjquan dyjprice dyjsale;cards;2000 jsj 1000 4500 4500000 dyj 800 2000 16000002001 jsj 1200 4000 4800000 dyj 1000 1500 1500000;例、2.2编制SAS程序如下:(1) data sasuser.class; input name$ sex$ age height weight; cards; Alice F 13 56.5 84 Becka M 13 65.3 98 Gail M 14 64.3 90 Karen F 12 56.3 77 ;(2) data sasuser.class; input name$ sex$ age height weight ; cards; Alice F 13 56.5 84 Becka M 13 65.3 98 Gail M 14 64.3 90 Karen F 12 56.3 77 ;(3) data sasuser.class; input name$ sex$ age height weight; cards; 艾丽丝 F 13 56.5 84 贝肯 M 13 65.3 98 盖尔 M 14 64.3 90 卡恩 F 12 56.3 77;例2.3 该问题的程序如下:data da2;infile c:test.dat ;input name$ sex$ chinese maths english physics chemisty;ave=( chinese+maths+ english+ physics+ chemisty)/5;(此行根据要求可不要)run;例2.4 Data da3;Set da2(drop=sex ave or keep= name chinese maths english physics chemisty);Total=sum(chinese,maths,english,physics,chemisty);Run;例2.5 程序如下data paixu;set sasuser.class;run;proc sort out=paixu1;by sex descending age;run;proc print data=paixu1;title 按性别和年龄排序;run;例2.6程序如下:data A;input name$20. state$ goods$ employ sale profit;cards;Thomson France Electronics 100 11917 2441Farmland Industries U.S. Food 11 4723 3255Chrysler U.S. Automobiles 128 43600 2551Volkswagen Germany Automobiles 252 46312 1232Nissan Motor Japan Automobiles 143 53760 805Borden U.S. Food 39 6700 6310Mazda Motor Japan Automobiles 33 20279 4541Westinghouse U.S. Electronics 102 11564 3260Amerada Hess U.S. Oil 10 5852 2680Peugeot France Automobiles 144 25670 258;proc sort out=sortA;by descending profit;run;proc transpose data=A;var state goods employ sale profit;id name;run;第三章例3.1 程序编辑如下:data a(drop=income1-income31);input income1-income31;mean=mean(of income1-income31);std=std(of income1-income31);skewness=skewness(of income1-income31);kurtosis=kurtosis(of income1-income31);cards;10349.69 8140.50 5661.16 4724.11 5129.05 5357.79 4810.00 4912.88 11718.00 6800.23 9279.16 5293.55 7432.26 5103.58 6489.97 4766.26 5524.54 6218.73 9761.51 5834.43 5358.32 6275.98 5894.27 5122.21 6324.64 7426.32 5124.24 4916.25 5169.96 4912.40 5644.86;proc print;run;例3.2 编程如下:data a(drop=i);do i=1 to 10 by 1;z=170+sqrt(30)*normal(0);output;end;例3.3 程序编辑如下:data class;input chinese maths english ;total=chinese+maths+english;if total>=240 then n+1;else delete;cards;82 78 69 90 78 89 79 86 98 76 56 80 72 76 81 69 78 91 92 71 85;例3.4 程序如下data class ;input name$ chinese maths english ;score=chinese;output;score=maths;output;score=english;output;cards;a 82 78 69 b 90 78 89 c 79 86 98 ;例3.5 程序如下:data class1 class2;input name$ chinese maths english ;total=chinese+maths+english;if total>=240 then output class1;else output class2;cards;a 82 78 69 b 90 78 89 c 79 86 98;proc print data=class1;title 数据集class1 ;proc print data=class2;title 数据集class2 ;run;例3.6 data class3 ;input sex$ chinese maths english ;if sex=m then delete;cards;m 82 78 69 f 90 78 89 m 79 86 98;例3.7:data class(keep=name total) class1(drop=name total) class2(drop=SEX); input name$ sex$ chinese maths english ;drop sex;total=chinese+maths+english;cards;a f 82 78 69 b m 90 78 89 c f 79 86 98;例3.8 data class ;input sex$ chinese maths english ;cards;m 82 . 69 f 90 0 89 m 79 86 98;data class1;set class;where maths;run;proc print;run;例3.9 data class ;input sex$ chinese maths english ;total=chinese+maths+english;cards;m 82 78 69 f 90 78 89 m 79 86 98;data class1;set class;where total> 180;where same and t