Can I use the NWAY option in PROC SUMMARY to implement the SAS principle of summarizing data using the SUM statement, grouping data with the BY statement, and calculating statistics with the VAR statement?

Can I use the NWAY option in PROC SUMMARY to implement the SAS principle of summarizing data using the SUM statement, grouping data with the BY statement, and calculating statistics with the VAR statement?

The NWAY option in PROC SUMMARY allows for the implementation of the SAS principle of summarizing data using the SUM statement, grouping data with the BY statement, and calculating statistics with the VAR statement. This option allows for the creation of a single observation for each unique combination of BY variables, with the SUM statement calculating the total for each variable and the VAR statement calculating the desired statistics. This approach ensures efficient and accurate summary of data, making it a valuable tool for data analysis and reporting.

SAS: Use NWAY in PROC SUMMARY


You can use the NWAY statement in PROC SUMMARY in SAS to only calculate summary statistics at a group level rather than calculating them for an entire dataset.

The following example shows how to use the NWAY statement in practice.

Example: How to Use NWAY in PROC SUMMARY

For this example, we’ll use the SAS built-in dataset called , which contains various measurements for 159 different fish caught in a lake in Finland.

We can use PROC PRINT to view the first 10 from this dataset:

/*view first 10 observations from Fish dataset*/
proc printdata=sashelp.Fish (obs=10);

run;

We can use the following code with PROC SUMMARY to calculate descriptive statistics for the variable Weight, grouped by the variable Species:

/*calculate descriptive statistics for Weight, grouped by Species*/
proc summarydata=sashelp.Fish;
    var Weight;class Species;  
    output out=summaryWeight;
run;

/*print output dataset*/
proc printdata=summaryWeight;

Note: There are a total of 40 rows in the output but we’ve only taken a screenshot of the first 20 rows.

Here’s how to interpret the output table:

  • _TYPE_: This column shows whether or not every row in the dataset was used to calculate the descriptive statistics. 0 = Every row was used.
  • _FREQ_: The number of rows used to calculate each descriptive statistic.
  • _STAT_: The name of the descriptive statistic.
  • Weight: The numerical value for the corresponding descriptive statistic.

The first five rows show summary statistics for the entire dataset.

For example:

  • The total number of observations was 158.
  • The minimum weight value was 0.
  • The maximum weight value was 1,650.
  • The mean weight value was 398.70.
  • The standard deviation of weight values was 359.09.

The next five rows show these summary statistics only for the rows in the dataset where the Species is equal to Bream.

And so on.

If we use the NWAY statement in PROC SUMMARY, we specify that we only want to display the rows with the highest value in the _TYPE_ column of the output.

This means that only rows with a value of 1 in the _TYPE_ column will be shown. In other words, the first five rows that show summary statistics for the entire dataset will no longer be shown.

The following code shows how to use the NWAY statement in practice:

/*calculate descriptive statistics for Weight, grouped by Species*/
proc summarydata=sashelp.Fish nway;
    var Weight;class Species;  
    output out=summaryWeight;
run;

/*print output dataset*/
proc printdata=summaryWeight;

Notice that the summary statistics for the entire dataset are no longer shown.

Only the summary statistics for the individual Species are shown.

The following tutorials explain how to perform other common tasks in SAS:

Cite this article

stats writer (2024). Can I use the NWAY option in PROC SUMMARY to implement the SAS principle of summarizing data using the SUM statement, grouping data with the BY statement, and calculating statistics with the VAR statement?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/can-i-use-the-nway-option-in-proc-summary-to-implement-the-sas-principle-of-summarizing-data-using-the-sum-statement-grouping-data-with-the-by-statement-and-calculating-statistics-with-the-var-state/

stats writer. "Can I use the NWAY option in PROC SUMMARY to implement the SAS principle of summarizing data using the SUM statement, grouping data with the BY statement, and calculating statistics with the VAR statement?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/can-i-use-the-nway-option-in-proc-summary-to-implement-the-sas-principle-of-summarizing-data-using-the-sum-statement-grouping-data-with-the-by-statement-and-calculating-statistics-with-the-var-state/.

stats writer. "Can I use the NWAY option in PROC SUMMARY to implement the SAS principle of summarizing data using the SUM statement, grouping data with the BY statement, and calculating statistics with the VAR statement?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/can-i-use-the-nway-option-in-proc-summary-to-implement-the-sas-principle-of-summarizing-data-using-the-sum-statement-grouping-data-with-the-by-statement-and-calculating-statistics-with-the-var-state/.

stats writer (2024) 'Can I use the NWAY option in PROC SUMMARY to implement the SAS principle of summarizing data using the SUM statement, grouping data with the BY statement, and calculating statistics with the VAR statement?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/can-i-use-the-nway-option-in-proc-summary-to-implement-the-sas-principle-of-summarizing-data-using-the-sum-statement-grouping-data-with-the-by-statement-and-calculating-statistics-with-the-var-state/.

[1] stats writer, "Can I use the NWAY option in PROC SUMMARY to implement the SAS principle of summarizing data using the SUM statement, grouping data with the BY statement, and calculating statistics with the VAR statement?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. Can I use the NWAY option in PROC SUMMARY to implement the SAS principle of summarizing data using the SUM statement, grouping data with the BY statement, and calculating statistics with the VAR statement?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top