首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要使用迭代创建循环语句

需要使用迭代创建循环语句
EN

Stack Overflow用户
提问于 2019-06-05 07:51:39
回答 1查看 39关注 0票数 0

最近的选举要求邮寄政党资料小册子。我们想确定花了多少个小时向一个选民中的50,000名登记选民提供这些广告材料。

每个人可以携带100本小册子包,最初他们可以以1米/秒的速度行走,但每次递送时,它们的速度为0.01米/秒,最高可达1.8米/秒。在SAS中创建一个循环语句,其中包含20个迭代,如下所示:

a> 1.如果平均送货间隔为50米,则显示每次送货速度的增加和每个人的旅行距离。确保每次迭代都显示在结果表中。

  1. 添加一个条件,以确保速度不超过上面指定的最大值。在达到最大步行速度之前,运送了多少捆?

b>使用另一个代码步骤来确定交付所有100个小册子包所花费的总时间,以及这需要多长时间才能交付给所有50,000名选民。提示速度=距离/时间。

下面是1a和b的代码。

代码语言:javascript
复制
data q6;
speed =1;
do i = 1 to 20;
distance_in_meters +50;
speed+0.01;
bundles+100;
output;
end;
run;

data q6;
speed=1;
do i = 1 to 1000 until (speed>=1.8);
distance_in_meters + 50 ;
speed + 0.01;
bundles +100;
output;
end;
run;

我需要B的帮助

EN

回答 1

Stack Overflow用户

发布于 2019-06-08 15:04:46

老师问的问题规格有点模糊。

这需要多长时间

有时是一些技巧问题,人们用总工时来回答,而不是想要技巧答案,时间在时钟上。

对于第二部分,您需要在调整速度之前计算每个交付时间(time = 50 / speed),并累积(total_time + time)

例如:

代码语言:javascript
复制
--- LOG ---
Time (hms) per person to deliver 100 pamphlets: 0:58:26
Number of pamplets: 50000
Number of persons: 500
Total person time (hms) on delivery: 486:53:34
Time to deliver all items if all people start at same time: 0:58:26

%let ItemCount = 50000;
%let ItemsPerPerson = 100;
%let LoadedVelocity = 1; * m/s;
%let UnloadDistance = 50; * m;
%let UnloadVelocityIncrease = 0.01; * m/s;
%let VelocityMax = 1.8; * m/s;

data want_a1_perPerson;
  length index speedup distance speed 8.;
  speed = 1;
  distance = 0;
  do index = 1 to 20;
    * unload;
    speedup = ifn (speed < &VelocityMax, &UnloadVelocityIncrease, 0);
    speed + speedup;
    distance + &UnloadDistance;
    output;    
  end;
run;

data want_a2_perPerson;
  length index speedup distance speed load unloaded 8.;

  speed = 1;
  distance = 0;

  load = 100;
  unloaded = 0;

  do index = 1 by 1 until (speed >= &VelocityMax or load = 0);
    unloaded + 1;
    load + -1;

    speedup = ifn (speed < &VelocityMax, &UnloadVelocityIncrease, 0);
    speed + speedup;

    distance + &UnloadDistance;

    output;    
  end;
run;


data want_b;
  length index speedup distance speed load unloaded 8.;

  speed = 1;
  distance = 0;

  load = 100;
  unloaded = 0;

  do index = 1 by 1 until (load = 0);

    distance + &UnloadDistance;

    time_to_unload = &UnloadDistance / speed; * unit analysis: m / (m/s) = s;

    total_time + time_to_unload;

    unloaded + 1;
    load + -1;

    speedup = ifn (speed < &VelocityMax, &UnloadVelocityIncrease, 0);
    speed + speedup;

    output;
  end;

  personCount = &ItemCount / &ItemsPerPerson;
  personHours = personCount * total_time;

  putlog "Time (hms) per person to deliver 100 pamphlets: " total_time time7.;
  putlog "Number of pamplets: &ItemCount";
  putlog "Number of persons: " personCount;
  putlog "Total person time (hms) on delivery: " personHours time9.;
  putlog "Time to deliver all items if all people start at same time: " total_time time7.;
run;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56456257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档