【问题标题】:Quartiles in SAS included incorrect number of observationsSAS 中的四分位数包括不正确的观察次数
【发布时间】:2022-01-06 14:59:07
【问题描述】:

我正在尝试使用以下代码计算 SAS 代码中数据的四分位数:

PROC RANK data = final_states out = final_states percent;
    var poverty_rate;
    ranks pov_percentile;
    var semi_poverty_rate;
    ranks semi_pov_percentile;
RUN;

/*Create quartiles for poverty percentiles*/
DATA final_states; 
    set final_states;
    if pov_percentile <= 25 then pov_quart = 1;
    else if pov_percentile > 25 and pov_percentile <= 50 then pov_quart = 2;
    else if pov_percentile > 50 and pov_percentile <= 75 then pov_quart = 3;
    else pov_quart = 4;
RUN;

运行代码后,我使用以下命令运行了一个制表命令:

PROC FREQ final_states;
    tables pov_quart;
RUN;

我得到了以下结果:

pov_quart  Frequency
1          865
2          785
3          785
4          785

产生这些结果的代码有问题吗?

【问题讨论】:

  • 你有很多关系吗,可能是 0 或其他小数字?
  • 我使用 PROC SQL 进行了检查,第一个四分位数的最小值大于 0。我确实注意到第一个四分位数的最大值是 10.59,而第二个四分位数的最小值是 10.60。这可能是一个重要的数字问题吗?

标签: sas


【解决方案1】:

检查是否丢失。

DATA final_states; 
    set final_states;
    if not missing(pov_percentile) then do;
       if pov_percentile <= 25 then pov_quart = 1;
       else if pov_percentile > 25 and pov_percentile <= 50 then pov_quart = 2;
       else if pov_percentile > 50 and pov_percentile <= 75 then pov_quart = 3;
       else pov_quart = 4;
       end;
RUN;

【讨论】:

  • 我尝试了这段代码,但我仍然在两个变量中得到相同的分布。
  • @hpr 你一直在重复使用 FINAL_STATES,我猜 POV_QUART 是上次运行遗留下来的,假设你确实有缺失值。
猜你喜欢
  • 1970-01-01
  • 2022-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-02
  • 1970-01-01
相关资源
最近更新 更多