简体   繁体   中英

sas proc tabulate (freq)

I have the following question:

Some sample data:

data;
input id article sex count;
datalines;
1 139 1 2
2 139 2 2
3 146 2 1
4 146 2 2
5 146 1 0
6 111 2 10
6 111 1 1
;
run;

Now, I have this code:

proc tabulate;
freq count;
class article sex;
table article, sex /misstext='0';
run;

Is there any difference compared to the following code?

proc tabulate;
var count;
class article sex;
table article, sex*count;
run;

Or does does it exactly do the same thing? Which one is recommendable?

Take notice of the output produced by the run of the two tabulate variations.

在此处输入图片说明

For the data set at hand the results are the same, presented differently.

  • The first has sex class cells that are an implicit frequency ( N ) computation that is count weighted, also implicitly formatted as an integer. The implicits are default behavior in absence of other statements and options.
  • The second has sex class cells that are the computed sum of count , formatted with default 2 decimal places.

If the data set had additional var variables used in table , the statistical computations to perform, and the role of weighting, would be dependent on the nature of presentation you are making and the audience consuming it. You might want or not want 'count' frequency weighting affecting the statistical computations.

Ask 5 people for a recommendation, you might get 6!

From online documentation, compare the details of the FREQ statement to the WEIGHT statement:

FREQ variable ;

Required Argument

variable

  • specifies a numeric variable whose value represents the frequency of the observation. If you use the FREQ statement, then the procedure assumes that each observation represents n observations, where n is the value of variable. If n is not an integer, then SAS truncates it. If n is less than 1 or is missing, then the procedure does not use that observation to calculate statistics.
  • The sum of the frequency variable represents the total number of observations.

and

WEIGHT variable ;

Required Argument

variable

  • specifies a numeric variable whose values weight the values of the analysis variables. The values of the variable do not have to be integers. PROC TABULATE responds to weight values in accordance with the following table.
    0 : Counts the observation in the total number of observations
  • <0 : Converts the value to zero and counts the observation in the total number of observations
  • .missing : Excludes the observation

To exclude observations that contain negative and zero weights from the analysis, use EXCLNPWGT. Note that most SAS/STAT procedures, such as PROC GLM, exclude negative and zero weights by default.

Note: Prior to Version 7 of SAS, the procedure did not exclude the observations with missing weights from the count of observations.

Restrictions

  • To compute weighted quantiles, use QMETHOD=OS in the PROC statement.
  • PROC TABULATE will not compute MODE when a weight variable is active. Instead, try using PROC UNIVARIATE when MODE needs to be computed and a weight variable is active.

Interaction

  • If you use the WEIGHT= option in a VAR statement to specify a weight variable, then PROC TABULATE uses this variable instead to weight those VAR statement variables.

Tip

  • When you use the WEIGHT statement, consider which value of the VARDEF= option is appropriate. See the discussion of VARDEF=divisor and the calculation of weighted statistics in the Keywords and Formulas section of this document.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM