1

In SAS (through WPS Workbench), I am trying to get some frequency counts on my data using the popn field (populations as integers) as a weight.

proc freq data= working.PC_pops noprint; 
    by District;
    weight popn / zeros; 
    tables AreaType / out= _AreaType;
run;

However, when I run the code above, I am getting the following error pointing to my Weight statement:

ERROR: Found "/" when expecting ;
ERROR: Statement "/" is not valid

I have checked the syntax online and to include zero counts within my weighting, it definitely says to use the "/ zeros" option within the Weight statement, but SAS (WPS) is erroring? What am I doing wrong?

UPDATE: I have now discovered that the zeros option is not supported through WPS Workbench. Is there a workaround to this?

Joe
  • 62,789
  • 6
  • 49
  • 67
al_sweets
  • 136
  • 10

1 Answers1

-2

Given you're not using any of the advanced elements of PROC FREQ (the statistical tests), you may be better off using PROC TABULATE. That will allow you to define exactly what levels you want in your output, even if they have zero elements, using a few different methods. Here's a bit of a hacky solution, but it works (at least in SAS 9.4):

data class;
  set sashelp.class;
  weight=1;
  if age=15 then weight=0;
run;

proc freq data=class;
  weight weight/zeros;
  tables age;
run;


proc tabulate data=class;
  class age;
  var weight;
  weight weight; *note this is WEIGHT, but does not act like weight in PROC FREQ, so we have to hack it a bit by using it as an analysis variable which is annoying;
  tables age,sumwgt='Count'*weight=' '*f=2.0;
run;

Both give the identical result. You can also use a CLASSDATA set, which is a bit less hacky but I'm not sure how well it's supported in non-SAS:

proc sort data=class out=class_classdata(keep=age) nodupkey;
  by age;
run;

proc tabulate data=class classdata=class_classdata;
  class age;
  freq weight;  *note this is FREQ not WEIGHT;
  tables age,n*f=2.0/misstext='0';
run;
Joe
  • 62,789
  • 6
  • 49
  • 67
  • 1
    Your top example is using `weight \ zeros` within the `proc freq` statement which is my initial problem as it is unsupported? – al_sweets Dec 18 '18 at 10:01
  • I think you misunderstand my example. I wrote a TABULATE solution that mimics the FREQ solution, and show that by presenting both next to each other. In Base SAS, they give identical results, so perhaps WPS will support the TABULATE approach. – Joe Jan 23 '20 at 17:41