proc tabulate missing values SAS

为君一笑 提交于 2019-12-11 13:17:31

问题


I have the following code:

ods tagsets.excelxp file = 'G:\CPS\myworkwithoutmissing.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;

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?


回答1:


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.

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.

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.

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.



来源:https://stackoverflow.com/questions/35425062/proc-tabulate-missing-values-sas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!