SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 685|回复: 1
打印 上一主题 下一主题

sas 强人帮我看看这个怎么写 为什么我怎么写 Y都是错的呢 5555555

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2009-9-12 13:43:33 | 只看该作者

sas 强人帮我看看这个怎么写 为什么我怎么写 Y都是错的呢 5555555

During World War II German submarines (U-boats) patrolled the Atlantic ocean looking for enemy ships to sink. Suppose a U-boat has 16 torpedoes (underwater missiles) to start off with when they left their U-boat pens in occupied France.
Suppose that each U-boat attack on an enemy ship uses 1 torpedo with probability 0.7, 2 torpedoes with probability 0.2, and 3 torpedoes with probability 0.1. (This is because big targets may require more hits and some torpedoes miss their target etc.)
We wish to estimate Y = the total number of enemy ships that will be attacked until the U-boat has run out of torpedoes. This includes the last ship even if there aren‟t enough torpedoes to sink it.
(a) Write a SAS program to simulate the distribution of Y. Perform 1000 simulations. If you wish to write a SAS macro then you may assume that the code below has been given to you and your code to be inserted at the position of the /*******/. Alternatively, you could attempt to do the simulation entirely within a data step.

%MACRO uboat(numiters);
%DO iter=1 %TO &numiters;
/**********/
/* Append results to dataset simout */ DATA simout; %IF &iter=1 %THEN %DO; SET sim; %END; %ELSE %DO; SET simout sim; %END; RUN; %END; /* End of %DO loop */
PROC MEANS DATA=simout; VAR Y; TITLE "Summary statistics of the ships attacked; &numiters iterations"; RUN;
PROC FREQ DATA=simout;
TABLES Y; RUN;
%MEND(uboat);
%uboat(1000);
(b) What statistical and/or practical assumptions have you made in (a)?
(c) Suppose you run your program (and it works) and your output is given below. Estimate E(Y).
Summary statistics of the ships attacked; 1000 iterations
The MEANS Procedure
Analysis Variable : Y
N Mean Std Dev Minimum Maximum
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
1000 11.6720000 1.5750863 7.0000000 16.0000000
Ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
Summary statistics of the ships attacked; 1000 iterations
The FREQ Procedure
Cumulative Cumulative
Y Frequency Percent Frequency Percent
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
7 2 0.20 2 0.20
8 15 1.50 17 1.70
9 71 7.10 88 8.80
10 146 14.60 234 23.40
11 212 21.20 446 44.60
12 260 26.00 706 70.60
13 163 16.30 869 86.90
14 99 9.90 968 96.80
15 30 3.00 998 99.80
16 2 0.20 1000 100.00
(d) At one time during the course of the war there were 200 U-boats operating in the Atlantic. Suppose they all attacked one (different) ship each on the same day, and that all U-boats had at least 3 torpedoes each initially. On average, how many torpedoes in total would be used that day? You may assume the above assumptions hold.
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2009-9-12 23:17:44 | 只看该作者

Re: sas 强人帮我看看这个怎么写 为什么我怎么写 Y都是错的呢 5555555

[code:33zncy6s]
ships=0;
missiles=0;
do until (missiles>=16);*number of missiles may be presumably more than 16,that should be Okay;
  ran=ranuni(0);  
  missiles+ifn(ran<=0.7,1,ifn(ran<=0.9,2,3));*at last attack, u-boat may need more missiles than number of missiles left,but that still counts;
  ships+1;
end;
[/code:33zncy6s]

*i dont have SAS at home thus not able to test it
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2026-2-6 00:45 , Processed in 0.066857 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表