1
votes

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?

1
Hard code it unfortunately. WPS is like using a 20 year old version of SAS. - Reeza

1 Answers

-2
votes

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;