proc 列出缺失值 SAS [英] proc tabulate missing values SAS

查看:36
本文介绍了proc 列出缺失值 SAS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

ods tagsets.excelxp file = 'G:CPSmyworkwithoutmissing.xml'
style = printer;
proc tabulate data = final;
Class Year Self_Emp_Inc Self_Emp_Uninc Self_Emp Multi_Job P_Occupation Full_Part_Time_Status;
table Year, P_Occupation*n;
table Year, (P_Occupation*Self_Emp_Inc)*n;
table Year, (Self_Emp_Inc*P_Occupation)*n;
run;
ods tagsets.excelxp close;

当我运行此代码时,我收到以下错误消息:

When I run this code, I get the following error message:

WARNING: A class, frequency, or weight variable is missing on every observation.
WARNING: A class, frequency, or weight variable is missing on every observation.
WARNING: A class, frequency, or weight variable is missing on every observation.

现在为了规避这个问题,我在类语句的末尾添加了缺失"选项,这样:

Now in order to circumvent this issue, I add the "missing" option at the end of the class statement such that:

class year self_emp_inc ....... Full_Part_Time_Status/ missing;

这解决了问题,因为它没有给我错误消息并创建表.但是,我的图表现在还计算了缺失值的数量,这是我不想要的.例如,我的变量 self_emp_inc 的值为 1 和 .(表示缺失).现在,当我使用缺少的选项运行代码时,我也得到了所有缺失值的 P_Occupation 计数,但我只想要 self_emp_Inc 的值为 1 时的计数.我怎样才能完成该任务?

This fixes the problem in that it doesn't give me the error message and creates the table. However, my chart now also counts the number of missing values, something that I do not want. For example my variable self_emp_inc has values of 1 and .(for missing). Now when I run the code with the missing option,I get a count of P_Occupation for all the missing values as well, but I only want the count for when the value of self_emp_Inc is 1. How can I accomplish that task?

推荐答案

这是 SAS 中令人沮丧的事情之一,出于某种原因 SAS 没有给我们一个好的"选项来解决.根据您的工作情况,有一些解决方案.

This is one of those frustrating things in SAS that for some reason SAS hasn't given us a "good" option to work around. Depending on what you're working with, there are a few solutions.

这里真正的问题不是你有缺失 - 在 1x1 表中(1 var x 1 var),排除缺失是你想要的.这是因为您正在调用多个表,并且每个表都受到另一个表中类变量缺失的影响.

The real problem here is not that you have missings - in a 1x1 table (1 var by 1 var), excluding missings is what you want. It's because you're calling for multiple tables and each table is affected by missings in the class variables in the other table.

因此,通常最简单的答案是将表拆分为多个 proc tabulate 语句.就运行时间而言,这有时可能过于复杂或过于繁重,但我怀疑大多数时候这是最好的解决方案 - 无论如何,它通常适合我.

As such, oftentimes the easiest answer is simply to split the tables into multiple proc tabulate statements. This might occasionally be too complicated or too onerous in terms of runtime, but I suspect the majority of the time this is the best solution - it often is for me, anyway.

由于您只使用 n,因此您可以构建包含缺失的列表,输出到数据集,然后将它们过滤掉并重新打印或导出该数据集.这通常是最简单的解决方案.

Since you're only working with n, you could instead construct the tabulation with the missings, output to a dataset, then filter them out and re-print or export that dataset. That's the easiest solution, typically.

您究竟想如何做到这一点当然取决于您到底想要什么.例如:

How exactly you want to do this of course depends on what exactly you want. For example:

data test_cars;
  set sashelp.cars;
  if _n_=5 then call missing(make);
  if _n_=7 then call missing(model);
  if _n_=10 then call missing(type);
  if _n_=13 then call missing(origin);
run;

proc tabulate data=test_cars out=test_tabulate(rename=n=count);
  class make model type origin/missing;
  tables (make model type),origin*n;
run;

data test_tabulate_want;
  set test_tabulate;
  if cmiss(of make model type origin)>2 then delete;
  length colvar $200;
  colvar = coalescec(of make model type);
run;

proc tabulate data=test_tabulate_want missing;
  class colvar origin/order=data;
  var count;
  tables colvar,origin*count*sum;
run;

这并不完美,尽管在格式方面做更多工作可以做得更好——这只是一个简单的例子.

This isn't perfect, though it can be made a lot better with some more work on the formatting - this is just a quick example.

如果您使用百分比,当然,这并不完全有效.您要么需要在该数据步骤中重构百分比 - 这有点工作,但可行 - 或者您需要为每个类变量单独制作表格.

If you're using percents, of course, this doesn't exactly work. You either need to refactor the percents in that data step - which is a bit of work, but doable - or you need separate tabulates for each class variable.

这篇关于proc 列出缺失值 SAS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆