用特定条件替换SAS中的缺失值

时间:2018-05-09 10:33:55

标签: sas proc-sql

我有一个名为 Planes 的大型数据集,在到达延迟(Arr_Delay)中缺少值。我想要 将特定路线(原点 - 目的地)上的平均延迟替换为特定的缺失值 载体

以下是数据集的示例: -

date      carrier  Flight    tailnum    origin  dest  Distance Air_time Arr_Delay

01-01-2013  UA     1545       N14228    EWR      IAH    1400    227        17
01-01-2013  UA     1714       N24211    LGA      IAH    1416    227        .
01-01-2013  AA     1141       N619AA    JFK      MIA    1089    160        .
01-01-2013  EV     5708       N829AS    LGA      IAD    229     53        -18
01-01-2013  B6     79         N593JB    JFK      MCO    944     140        14
01-01-2013  AA     301        N3ALAA    LGA      ORD    733     138        .
01-01-2013  B6     49         N793JB    JFK      PBI    1028    149        .
01-01-2013  B6     71         N657JB    JFK      TPA    1005    158        19
01-01-2013  UA     194        N29129    JFK      LAX    2475    345        23
01-01-2013  UA     1124       N53441    EWR      SFO    2565    361       -29
我试过

代码: -

 Proc stdize data=cs1.Planes reponly method=mean out=cs1.Complete_data;
 var Arrival_delay_minutes;                                                                                                                                                                                                                                     
 Run; 

但是,正如我的问题所述......我希望通过特定路线和特定航母获得失踪价值的平均值。请帮帮我!

2 个答案:

答案 0 :(得分:1)

stdize过程没有办法包含by或类变量。您可以使用以下代码完成任务: -

Proc means data=cs1.Planes  noprint;
 var Arr_Delay;
 class carrier origin dest;
 output out=mean1;
Run;

proc sort data=cs1.Planes;
  by carrier origin dest;
run;

proc sort data=mean1;
  by carrier origin dest;
run;

data cs1.Complete_data(drop=Arr_Delay1 _stat_);
  merge cs1.Planes(in=a) mean1(where=(_stat_="MEAN")
                    keep=carrier origin dest Arr_Delay _stat_
                    rename=(Arr_Delay = Arr_Delay1) in=b);
  by carrier origin dest;
  if a;
  if Arr_Delay =. then Arr_Delay=Arr_Delay1;
run;

答案 1 :(得分:1)

您只需按来源,目标和广告对表格Error: Uncaught (in promise): TypeError: browser.addEventListener is not a function TypeError: browser.addEventListener is not a function at http://localhost:8100/build/main.js:74:21 at t.invoke (http://localhost:8100/build/polyfills.js:3:14976) at Object.onInvoke (http://localhost:8100/build/vendor.js:5134:33) at t.invoke (http://localhost:8100/build/polyfills.js:3:14916) at r.run (http://localhost:8100/build/polyfills.js:3:10143) at http://localhost:8100/build/polyfills.js:3:20242 at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660) at Object.onInvokeTask (http://localhost:8100/build/vendor.js:5125:33) at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15581) at r.runTask (http://localhost:8100/build/polyfills.js:3:10834) at c (http://localhost:8100/build/polyfills.js:3:19752) at http://localhost:8100/build/polyfills.js:3:20273 at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660) at Object.onInvokeTask (http://localhost:8100/build/vendor.js:5125:33) at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15581) at r.runTask (http://localhost:8100/build/polyfills.js:3:10834) at o (http://localhost:8100/build/polyfills.js:3:7894) at e.invokeTask [as invoke] (http://localhost:8100/build/polyfills.js:3:16823) at p (http://localhost:8100/build/polyfills.js:2:27648) at HTMLDocument.v (http://localhost:8100/build/polyfills.js:2:27893) 进行排序运行cs1.Planes之前的运营商,并添加Proc stdize进行您想要的分组。值不会丢失的唯一情况是此运营商/路线没有其他值。

您可以找到SAS文档here和可用选项here

代码:

by  origin  dest carrier;