How can bar charts be created in SAS? 2

How can bar charts be created in SAS?

Bar charts can be easily created in SAS using the PROC GCHART statement. This statement allows for the creation of a variety of bar charts, including vertical, horizontal, stacked, and grouped bars. The data for the bar chart can be specified using a SAS data set or by manually entering the data values. Additional options can be added to customize the appearance of the bar chart, such as labels, titles, and colors. Overall, SAS provides a straightforward and efficient method for creating visually appealing bar charts for data analysis and presentation purposes.

Create Bar Charts in SAS (3 Examples)


You can use the following methods to create different types of bar charts in SAS:

Method 1: Create One Bar Chart

proc sgplot data = my_data;
    vbar variable1;
run;

Method 2: Create Stacked Bar Chart

proc sgplot data = my_data;
    vbar variable1 / group = variable2;
run;

Method 3: Create Clustered Bar Chart

proc sgplot data = my_data;
    vbar variable1 / group = variable2 groupdisplay = cluster;
run;

The following examples show how to use each method with the following dataset in SAS:

/*create dataset*/
data my_data;
    input team $ position $ points;
    datalines;
A Guard 8
A Guard 6
A Guard 6
A Forward 9
A Forward 14
A Forward 11
B Guard 10
B Guard 9
B Guard 5
B Forward 7
C Guard 10
C Forward 6
C Forward 8
;
run;/*view dataset*/
proc printdata=my_data;

Example 1: Create One Bar Chart

The following code shows how to create a bar chart to visualize the frequency of teams:

/*create bar chart to visualize frequency of teams*/
title "Bar Chart of Team Frequency";
proc sgplot data = my_data;
    vbar team;
run;

bar chart in SAS

If you’d like a horizontal bar chart instead, simply use the hbar option:

/*create horizontal bar chart to visualize frequency of teams*/
title "Bar Chart of Team Frequency";
proc sgplot data = my_data;
    hbar team;
run;

horizontal bar chart in SAS

Example 2: Create Stacked Bar Chart

The following code shows how to create a stacked bar chart to visualize the frequency of both team and position:

/*create stacked bar chart*/title "Stacked Bar Chart of Team & Position";
proc sgplot data = my_data;
    vbar team / group = position;
run;

stacked bar chart in SAS

This chart allows us to visualize the frequency of each team along with the frequency of positions within each team.

Example 3: Create Clustered Bar Chart

The following code shows how to create a clustered bar chart to visualize the frequency of both team and position:

/*create clustered bar chart*/title "Clustered Bar Chart of Team & Position";
proc sgplot data = my_data;
    vbar team / group = position groupdisplay = cluster;
run;

clustered bar chart in SAS

This bar chart displays the same information as the previous bar chart, except the bars are “clustered” together instead of stacked on top of each other.

Additional Resources

The following tutorials explain how to create other charts in SAS:

Cite this article

stats writer (2024). How can bar charts be created in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-bar-charts-be-created-in-sas/

stats writer. "How can bar charts be created in SAS?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-bar-charts-be-created-in-sas/.

stats writer. "How can bar charts be created in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-bar-charts-be-created-in-sas/.

stats writer (2024) 'How can bar charts be created in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-bar-charts-be-created-in-sas/.

[1] stats writer, "How can bar charts be created in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.

stats writer. How can bar charts be created in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

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