Table of Contents
Histograms are graphical representations of the distribution of data. In SAS, histograms can be created by using the PROC UNIVARIATE or PROC SGPLOT procedures. The PROC UNIVARIATE procedure allows for more customization of the histogram, while the PROC SGPLOT procedure offers a simpler method for creating a basic histogram.
Three examples of creating histograms in SAS are:
1. Using PROC UNIVARIATE:
a. Define the data set to be used.
b. Use the HISTOGRAM statement to specify the variable(s) to be plotted.
c. Optional: use the HISTOGRAM statement options to customize the histogram.
d. Run the PROC UNIVARIATE procedure to generate the histogram.
2. Using PROC SGPLOT:
a. Define the data set to be used.
b. Use the HISTOGRAM statement to specify the variable(s) to be plotted.
c. Optional: use the HISTOGRAM statement options to customize the histogram.
d. Run the PROC SGPLOT procedure to generate the histogram.
3. Using the SAS Visual Analytics interface:
a. Import the data set to be used.
b. Select the variables to be plotted in the histogram.
c. Optional: use the chart options to customize the histogram.
d. Generate and view the histogram.
The process for generating histograms in SAS involves defining the data set, specifying the variables to be plotted, and using the appropriate procedure to generate the histogram. Optional customization can be done using statement or chart options. The resulting histogram can then be viewed and saved for further analysis.
Create Histograms in SAS (3 Examples)
You can use the following methods to create one or more histograms in SAS:
Method 1: Create One Histogram
proc univariatedata=my_data; var var1; histogram var1; run;
Method 2: Create Panel of Histograms
proc univariatedata=my_data; class var2; var var1; histogram var1; run;
Method 3: Overlay Histograms
proc univariatedata=my_data; class var2; var var1; histogram var1 / overlay; run;
The following examples show how to use each method with the following dataset in SAS:
/*create dataset*/ data my_data; input team $ points rebounds; datalines; A 29 8 A 23 6 A 20 6 A 21 9 A 33 14 A 35 11 A 31 10 B 21 9 B 14 5 B 15 7 B 11 10 B 12 6 B 10 8 B 15 10 ; run;/*view dataset*/ proc printdata=my_data;

Example 1: Create One Histogram
The following code shows how to create one histogram for the points variable:
/*create histogram for points variable*/
proc univariatedata=my_data;
var points;
histogram points;
run;

The x-axis displays the values for the points variable and the y-axis displays the percentage of observations in the dataset that fall into various values.
Example 2: Create Panel of Histograms
The following code shows how to create a panel of histograms to visualize the distribution of values for the points variable grouped by the team variable:
/*create histogram for points variable*/
proc univariatedata=my_data;
class team;
var points;
histogram points;
run;
This plot allows us to quickly see that the players on team A tend to score more points than the players on team B.
Notice that the two histograms share an x-axis, which makes it easy to compare the points values between the two teams.
Method 3: Overlay Histograms
The following code shows how to overlay multiple histograms in one plot:
/*create histogram for points variable*/
proc univariatedata=my_data;
class team;
var points;
histogram points / overlay;
run;
This type of plot is useful when you want to visualize multiple histograms in a single chart.
Additional Resources
The following tutorials explain how to create other charts in SAS:
Cite this article
stats writer (2024). How can histograms be created in SAS? What are three examples of creating histograms in SAS? What is the process for generating histograms in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-histograms-be-created-in-sas-what-are-three-examples-of-creating-histograms-in-sas-what-is-the-process-for-generating-histograms-in-sas/
stats writer. "How can histograms be created in SAS? What are three examples of creating histograms in SAS? What is the process for generating histograms in SAS?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-histograms-be-created-in-sas-what-are-three-examples-of-creating-histograms-in-sas-what-is-the-process-for-generating-histograms-in-sas/.
stats writer. "How can histograms be created in SAS? What are three examples of creating histograms in SAS? What is the process for generating histograms in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-histograms-be-created-in-sas-what-are-three-examples-of-creating-histograms-in-sas-what-is-the-process-for-generating-histograms-in-sas/.
stats writer (2024) 'How can histograms be created in SAS? What are three examples of creating histograms in SAS? What is the process for generating histograms in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-histograms-be-created-in-sas-what-are-three-examples-of-creating-histograms-in-sas-what-is-the-process-for-generating-histograms-in-sas/.
[1] stats writer, "How can histograms be created in SAS? What are three examples of creating histograms in SAS? What is the process for generating histograms in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.
stats writer. How can histograms be created in SAS? What are three examples of creating histograms in SAS? What is the process for generating histograms in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
