Generation of a simple frequency chart for a variable ('TYPE') to visualize the distribution of its values.
Sorting values by descending frequency (ORDER=FREQ) and changing the chart orientation to horizontal bars (ORIENT=HORIZONTAL) for better readability.
Creation of bivariate frequency charts (cross-tables) where a distinct chart is produced for each value of the first variable, allowing analysis of the second variable's distribution by group.
Use of the TWOWAY=STACKED option for stacked bar charts in the context of cross-tables, offering a comparative view of proportions.
The script uses the integrated `sashelp.cars` dataset, which is a standard demonstration dataset available by default in the SAS environment and does not require external creation or management.
1 Code Block
PROC FREQ
Explanation : This code block generates a simple frequency chart for the 'TYPE' variable from the `sashelp.cars` dataset. The `plots=freqplot` option requests the creation of a visual bar chart representing the frequency of each unique value of the 'TYPE' variable.
Copied!
title "Frequency Distribution of TYPE";
proc freq data=sashelp.cars;
tables type / plots=freqplot;
run;
1
title "Frequency Distribution of TYPE";
2
PROC FREQDATA=sashelp.cars;
3
tables type / plots=freqplot;
4
RUN;
2 Code Block
PROC FREQ
Explanation : This block produces a frequency chart where the categories of the 'TYPE' variable are sorted by descending frequency (`order=freq` option). Additionally, the `plots=freqplot(orient=horizontal)` option changes the chart's orientation to display horizontal bars, potentially improving readability for certain distributions.
Copied!
title "Descending Frequency Distribution of TYPE";
proc freq data=sashelp.cars order=freq;
tables type / plots=freqplot(orient=horizontal);
run;
1
title "Descending Frequency Distribution of TYPE";
2
PROC FREQDATA=sashelp.cars order=freq;
3
tables type / plots=freqplot(orient=horizontal);
4
RUN;
3 Code Block
PROC FREQ
Explanation : This block illustrates the creation of a two-way frequency chart (a cross-table) for the 'ORIGIN' and 'TYPE' variables. The `plots=freqplot` option generates a distinct bar chart for each unique value of the 'ORIGIN' variable, showing the distribution of 'TYPE' within each origin.
Copied!
title "Two-way Frequency Distribution of TYPE and ORIGIN";
title2 "Separate Plots";
proc freq data=sashelp.cars;
tables origin*type / plots=freqplot;
run;
1
title "Two-way Frequency Distribution of TYPE and ORIGIN";
2
title2 "Separate Plots";
3
PROC FREQDATA=sashelp.cars;
4
tables origin*type / plots=freqplot;
5
RUN;
4 Code Block
PROC FREQ
Explanation : This last block presents an advanced two-way frequency chart with stacked bars (`twoway=stacked`) and a horizontal orientation. The bars are sorted by descending frequency (`order=freq`), and each stacked segment represents a 'TYPE' value within each 'ORIGIN', offering a visual comparison of the distributions of the two variables in an aggregated and detailed manner.
Copied!
title "Two-way Descending Frequency Distribution of TYPE and ORIGIN";
title2 "Stacked Bars";
proc freq data=sashelp.cars order=freq;
tables origin*type / plots=freqplot(twoway=stacked orient=horizontal);
run;
1
title "Two-way Descending Frequency Distribution of TYPE and ORIGIN";
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.