The script initializes two datasets, 'htwt' and 'Emart', by incorporating data directly via DATALINES blocks. It then utilizes PROC CHART to produce a series of visualizations: vertical and horizontal histograms for the categorical and numerical variables of the 'htwt' dataset, as well as bar charts for department frequencies, sales distribution, sales grouped by department, and the sum of sales by year from the 'Emart' dataset. Options such as `Midpoints`, `Group`, `Sumvar`, `Type`, `Discrete`, and formats are used to refine the presentation of the charts.
Data Analysis
Type : CREATION_INTERNE
The 'htwt' and 'Emart' datasets are entirely created within the SAS script using DATALINES statements, meaning all source data is internal to the program.
1 Code Block
DATA STEP Data
Explanation : This DATA STEP block creates the temporary dataset 'htwt' and inserts raw data using the DATALINES statement. It defines four variables: 'subject' (numeric), 'gender' (character), 'height' (numeric), and 'weight' (numeric).
Copied!
data htwt;
input subject gender $ height weight;
datalines;
1 M 68.5 155
2 F 61.2 99
3 F 63.0 115
4 M 70.0 205
5 M 68.6 170
6 F 65.1 125
7 M 72.4 220
8 M . 188
;
1
DATA htwt;
2
INPUT subject gender $ height weight;
3
DATALINES;
4
1 M 68.5155
5
2 F 61.299
6
3 F 63.0115
7
4 M 70.0205
8
5 M 68.6170
9
6 F 65.1125
10
7 M 72.4220
11
8 M . 188
12
;
2 Code Block
PROC CHART
Explanation : This PROC CHART generates a vertical bar chart for the 'gender' variable of the 'htwt' dataset. Each bar represents the frequency of the different 'gender' categories.
Copied!
proc chart data= htwt;
title "Bar chart from Proc Chart";
Vbar gender;
run;
1
PROC CHARTDATA= htwt;
2
title "Bar chart from Proc Chart";
3
Vbar gender;
4
RUN;
3 Code Block
PROC CHART
Explanation : This PROC CHART produces a vertical bar chart for the numerical variable 'height' of the 'htwt' dataset. The `Midpoints` option specifies the central points of the intervals to group height values, thereby creating a class distribution.
Copied!
proc chart data= htwt;
title "Bar chart from Proc Chart";
Vbar height / Midpoints=60 to 74 by 2;
run;
1
PROC CHARTDATA= htwt;
2
title "Bar chart from Proc Chart";
3
Vbar height / Midpoints=60 to 74BY2;
4
RUN;
4 Code Block
PROC CHART
Explanation : Similar to the previous block, this PROC CHART generates a bar chart but uses the `Hbar` statement for a horizontal display. It shows the distribution of 'height' with the same midpoints and includes a frequency table on the right side.
Copied!
* using Hbar statement replacing Vbar, there is frequency table showing up by the right side of the bar
proc chart data= htwt;
title "Bar chart from Proc Chart";
Hbar height / Midpoints=60 to 74 by 2;
run;
1
* using Hbar statement replacing Vbar, there is frequency table showing up by the right side of the bar
2
proc chart data= htwt;
3
title "Bar chart from Proc Chart";
4
Hbar height / Midpoints=60 to 74BY2;
5
RUN;
5 Code Block
DATA STEP Data
Explanation : This second DATA STEP block creates a new temporary dataset named 'Emart' from in-line data. It contains three variables: 'YEAR' (numeric), 'DEPT' (character), and 'SALES' (numeric).
Explanation : This PROC CHART displays a simple bar chart of the frequencies of the categorical variable 'dept' from the 'Emart' dataset. Each bar represents the number of occurrences of each department.
Copied!
Proc chart Data=Emart;
title "Simple Frequency Bar Chart";
vbar dept;
run;
1
PROC CHARTDATA=Emart;
2
title "Simple Frequency Bar Chart";
3
vbar dept;
4
RUN;
7 Code Block
PROC CHART
Explanation : This PROC CHART generates a bar chart for the numerical variable 'sales' of the 'Emart' dataset, showing the distribution of sales values as frequency bars.
Copied!
proc chart data=emart;
title "Bar Chart on a Numerical Variable (Sales)";
VBAR sales;
run;
1
PROC CHARTDATA=emart;
2
title "Bar Chart on a Numerical Variable (Sales)";
3
VBAR sales;
4
RUN;
8 Code Block
PROC CHART
Explanation : This block uses `pattern` to define the fill style of the bars (black L2 line). The subsequent PROC CHART creates a vertical bar chart of the 'sales' variable, grouped (`Group=`) by 'Dept'. Sales are displayed with specific midpoints and formatted as currency.
Copied!
pattern value=L2 color=black;
proc chart data=emart;
title "Distributiion of sales by Department";
Vbar sales /Group= Dept Midpoints=4500 to 5500 by 1000;
format sales dollar8.0;
run;
1
pattern value=L2 color=black;
2
PROC CHARTDATA=emart;
3
title "Distributiion of sales by Department";
4
Vbar sales /Group= Dept Midpoints=4500 to 5500BY1000;
5
FORMAT sales dollar8.0;
6
RUN;
9 Code Block
PROC CHART
Explanation : This PROC CHART generates a bar chart that visualizes the sum (`type=sum`, `sumvar=sales`) of sales by 'year'. The `discrete` option ensures that the year is treated as a distinct categorical variable. Sales are formatted as currency.
Copied!
proc chart data=emart;
title "Sum of Sales by Year";
vbar year /sumvar=sales type=sum discrete;
* TPYE= FREQ PCT CFREQ CPCT SUM MEAN (Frequncy, Percent, Cumulative Freq, Cumulative Pct, sum, mean)
format sales dollar8.;
run;
1
PROC CHARTDATA=emart;
2
title "Sum of Sales by Year";
3
vbar year /sumvar=sales type=sum discrete;
4
* TPYE= FREQ PCT CFREQ CPCT SUM MEAN (Frequncy, Percent, Cumulative Freq, Cumulative Pct, sum, mean)
5
format sales dollar8.;
6
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.