- SAS Tutorial
- SAS - Home
- SAS - Overview
- SAS - Environment
- SAS - User Interface
- SAS - Program Structure
- SAS - Basic Syntax
- SAS - Data Sets
- SAS - Variables
- SAS - Strings
- SAS - Arrays
- SAS - Numeric Formats
- SAS - Operators
- SAS - Loops
- SAS - Decision Making
- SAS - Functions
- SAS - Input Methods
- SAS - Macros
- SAS - Dates & Times
- SAS Data Set Operations
- SAS - Read Raw Data
- SAS - Write Data Sets
- SAS - Concatenate Data Sets
- SAS - Merging Data Sets
- SAS - Subsetting Data Sets
- SAS - Sort Data Sets
- SAS - Format Data Sets
- SAS - SQL
- SAS - Output Delivery System
- SAS - Simulations
- SAS Data Representation
- SAS - Histograms
- SAS - Bar Charts
- SAS - Pie Charts
- SAS - Scatterplots
- SAS - Boxplots
- SAS Basic Statistical Procedure
- SAS - Arithmetic Mean
- SAS - Standard Deviation
- SAS - Frequency Distributions
- SAS - Cross Tabulations
- SAS - T Tests
- SAS - Correlation Analysis
- SAS - Linear Regression
- SAS - Bland-Altman Analysis
- SAS - Chi-Square
- SAS - Fishers Exact Tests
- SAS - Repeated Measure Analysis
- SAS - One-Way Anova
- SAS - Hypothesis Testing
- SAS Useful Resources
- SAS - Quick Guide
- SAS - Useful Resources
- SAS - Questions and Answers
- SAS - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
SAS - Bar Charts
A bar chart represents data in rectangular bars with length of the bar proportional to the value of the variable. SAS uses the procedure PROC SGPLOT to create bar charts. We can draw both simple and stacked bars in the bar chart. In bar chart each of the bars can be given different colors.
Syntax
The basic syntax to create a bar-chart in SAS is −
PROC SGPLOT DATA = DATASET; VBAR variables; RUN;Following is the description of parameters used −
DATASET − is the name of the dataset used.
variables − are the values used to plot the histogram.
Simple Bar chart
A simple bar chart is a bar chart in which a variable from the dataset is represented as bars.
Example
The below script will create a bar-chart representing the length of cars as bars.
PROC SQL; create table CARS1 as SELECT make, model, type, invoice, horsepower, length, weight FROM SASHELP.CARS WHERE make in ('Audi','BMW') ; RUN; proc SGPLOT data = work.cars1; vbar length ; title 'Lengths of cars'; run; quit;
When we execute the above code, we get the following output −
Stacked Bar chart
A stacked bar chart is a bar chart in which a variable from the dataset is calculated with respect to another variable.
Example
The below script will create a stacked bar-chart where the length of the cars are calculated for each car type. We use the group option to specify the second variable.
proc SGPLOT data = work.cars1; vbar length /group = type ; title 'Lengths of Cars by Types'; run; quit;
When we execute the above code, we get the following output −
Clustered Bar chart
The clustered bar chart is created to show how the values of a variable are spread across a culture.
Example
The below script will create a clustered bar-chart where the length of the cars is clustered around the car type.So we see two adjacent bars at length 191, one for the car type 'Sedan' and another for the car type 'Wagon'.
proc SGPLOT data = work.cars1; vbar length /group = type GROUPDISPLAY = CLUSTER; title 'Cluster of Cars by Types'; run; quit;
When we execute the above code, we get the following output −