1
votes

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
I can't try this so I'll comment for now. You can have multiple CLASS statements and have missing only on the values of interest. You can also use a WHERE statement to restrict your analysis. - Reeza
I actually only used the "missing" option to see if that fixes the problem. I though proc tabulate by default ignores the missing values, but it seems to be an issue in this case. Not sure why. I actually want to ignore the missing value in all cases and in all the variables. - user2916331
Proc tabulate excludes cases listwise. Any variables listed having a missing value causes the observation to be excluded from all analysis. - Reeza
So what should be done then? Should I write a separate class statement for each variable? - user2916331
Try a proc tabulate for each table statement limiting your variables to the minimum necessary. I'm just guessing at this point though - you should post sample data that replicates your issues. - Reeza

1 Answers

1
votes

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.