Plots Freqplot Sas

Posted : admin On 4/15/2022

Years ago, I wrote an article about how to create a Top 10 table and bar chart. The program can be trivially modified to create a 'Top N' table and plot, such as Top 5, Top 20, or even Top 100. Not long after the article was written, the developer of PROC FREQ (who had read my blog post) implemented the MAXLEVELS= option on the TABLES statement in PROC FREQ in SAS 9.4. The MAXLEVELS= option automatically creates these tables and plots for you! The option applies only to one-way tables, not to cross tabulations.

The most basic usage of Proc Freq is to determine the frequency (number of. The PLOTS= option has a common overall syntax for all statistical procedures, but the specific global plot options, plot requests, and plot options vary across procedures. This section discusses only a few of the options available in the PLOTS= option. Then I'm going to add the PLOTS=FREQPLOT option to create a frequency plot. I'm going to format IncidentDate by the YEAR format. And then lastly, I'm only going to include rows where DateIssues is null, that is, only rows without a date issue will be included in the procedure. Many SAS regression procedures (and PROC PLM) create effect plots. PROC SURVEYREG creates a hexagonal bin plot. PROC REG creates heat maps when a scatter plot would suffer from overplotting. PROC LOGISTIC creates odds-ratio plots. When you have enabled ODS Graphics, you can request specific plots with the PLOTS= option in the TABLES statement. If you do not specify the PLOTS= option but have enabled ODS Graphics, then PROC FREQ produces all plots that are associated with the analyses that you request.

A Top 10 plot and bar chart

Plots Freqplot Sas

Suppose you want to see the Top 10 manufacturers of vehicles in the Sashelp.Cars data set. The following call to PROC FREQ uses the MAXLEVELS=10 option to create a Top 10 table and a bar chart of the 10 manufacturers who appear most often in the data:


A few comments about the MAXLEVELS= option:

  • The option affects only the display of the table and chart. The statistics (cumulative counts, percentages, chi-square tests,...) are all based on the full data and all categories. Similarly, if you use the OUT= option to write the counts to an output data set, the data set will contain the counts for all categories, not just the top categories.
  • The 'OneWayFreqs' table contains a note at the bottom to remind you that you are looking at a partial table. You can also see that the 'Cumulative Percent' column does not end at 100.
  • The PLOTS=FREQPLOT option contains suboptions that you can use to control aspects of the plot. For example, if you want a horizontal bar chart that shows percentages instead of counts, use the option plots=FreqPlot(orient=horizontal scale=percent).

Sometimes a small change can make a big difference. Although it is not difficult to follow the steps in the original article to create a Top 10 table and chart, the MAXLEVELS= option is even easier.

Plots freqplot sas 3

A Top 10 plot with an 'Others' category

For completeness, the following statements are reproduced from an earlier article that shows how to merge the low-frequency categories into a new category with the value 'Others.' The resulting bar chart shows the most frequent categories and lumps the others into an 'Others' category.

Plots Freqplot Sas Function

Sas

Plots Freqplot Sas 2

In the second PROC FREQ analysis, the smaller categories are merged into a new category called 'Others.' The 'Others' category is suitable for tabular and graphical reporting, but you should think carefully before running statistical tests. As this example shows, the distribution of the new categorical variable might be quite different from the distribution of the original variable.