【发布时间】:2015-04-10 15:19:30
【问题描述】:
我正在运行一个模拟来预测汽车经销商的库存。经销商在 10% 的时间里销售零辆汽车,一辆汽车 50%,两辆汽车 30%,三辆汽车 10%。在销售的这些汽车中,50% 是轿车,30% 是 SUV,20% 是卡车。此外,所售汽车的型号如下:
- 轿车:30% 为“S”,40% 为“SE”,30% 为“SEL”
- SUV:25% 为“S”,35% 为“SE”,40% 为“SEL”
- 卡车:50% 为“S”,30% 为“SE”,20% 为“SEL”
我正在尝试生成这些最后的模型分布,但我的代码整天都打印“S”。各位能给点建议吗?谢谢!
这是文本中的代码:
data cars (drop=perc_sales car_type_perc subtype_perc);
format date date9.;
date='01Jan2016'd;
do until (date > '31Dec2016'd);
if
weekday(date) not in (1)
and date not in ('01Jan2016'd,'04Jul2016'd,'25Dec2016'd)
then output;
date=intnx('day',date,1);
S_price1 = 15000+200*rand('normal'); *Sedan;
S_price2 = 30000+500*rand('normal'); *SUV;
S_price3 = 25000+300*rand('normal'); *Truck;
perc_sales = rand('uniform');
car_type_perc = rand('uniform');
subtype_perc = rand('uniform');
if 0 < perc_sales <= 0.1 then Ncars = 0; * 10% chance zero cars sold;
if 0.1 < perc_sales <= 0.6 then Ncars = 1; * 50% chance one car sold;
if 0.6 < perc_sales <= 0.9 then Ncars = 2; * 30% chance two cars sold;
if 0.9 < perc_sales <= 1 then Ncars = 3; * 10% chance three cars sold;
if 0 < car_type_perc <= 0.5 then type = 'Sedan'; * 50% of cars sold are sedans;
if 0.5 < car_type_perc <= 0.8 then type = 'SUV'; * 30% of cars sold are SUVs;
if 0.8 < car_type_perc <= 1 then type = 'Truck'; * 20% of cars sold are trucks;
if type = 'Sedan' and 0 < rand('uniform') <= 0.3 then model = 'S';
if type = 'Sedan' and 0.3 < rand('uniform') <= 0.7 then model = 'SE';
if type = 'Sedan' and 0.7 < rand('uniform') <= 1 then model = 'SEL';
if type = 'SUV' and 0 < rand('uniform') <= 0.25 then model = 'S';
if type = 'SUV' and 0.25 < rand('uniform') <= 0.6 then model = 'SE';
if type = 'SUV' and 0.6 < rand('uniform') <= 1 then model = 'SEL';
if type = 'Truck' and 0 < rand('uniform') <= 0.5 then model = 'S';
if type = 'Truck' and 0.5 < rand('uniform') <= 0.8 then model = 'SE';
if type = 'Truck' and 0.8 < rand('uniform') <= 1 then model = 'SEL';
end;
run;
【问题讨论】:
-
代码应该作为文本输入,而不是图片 - 我无法将图片复制并粘贴到我的编辑器中(好吧,让它做任何有用的事情)。
-
很抱歉 - 我不知道我可以使用 ctrl+k 来更轻松地粘贴。
标签: model statistics sas simulation