Hi,
I want to compare overall data with a subset.
I could do this overlaying histograms thanks to these great answers.
That was for continuous data. Can the same be done with nominal and ordinal data in a grouped Pie chart or barplot?
Thanks
If your data is grouped, and you want to compare the values side by side by Category, you can use the Proc SGPLOT VBAR statement or the Proc GCHART VBAR statement.
proc sgplot data=sashelp.cars;
vbar origin / response=mpg_city group=type groupdisplay=cluster stat=mean;
run;
Thanks for answering.
This is not exactly what I'm looking for. I want to compare the distribution of a subgroup with the overall distribution.
Let's take an example.
Assuming I have different clusters of customers, I want to see what are the characteristics of each one.
This can be done by comparing the distribution of each cluster with the overall distribution.
For example, for cluster1, I compare its countries' proportions to all data countiries' proportions.
A pie chart grouping both proportions can be visually easier to compare than two side by side pie charts.
Hope my example is clear
+1 for the butterfly chart. Here is an example: http://support.sas.com/kb/35/051.html
Thx @pearsoninst and @DanH_sas ! Great idea.
However, I didn't find yet how to do this with all the data and a subset in the same graphic. And this is the hardest part.
I think it can be done with proc template.
Regardless of whether you use SGPLOT or GTL/SGRENDER, the data manipulation is the same:
1. Create a dataset with the subset data extracted from the original data, keeping only the columns necessary for the chart.
2. Rename the kept columns in the new dataset to something different from the orginal data column names.
3. Create a new dataset that is a "straight" merge (not "match-merge") of the subset data and the original data.
4. Use this merged dataset in either SGPLOT or SGRENDER.
Hope this helps!
Dan
One benefit with GTL is you can use the EVAL feature using IFC and IFN functions (and othe rways) to do subsetting of data on the fly inside the template.
Thank you @pearsoninst, @DanH_sas and @Jay54 for your help. Very instructive !
I finally used a butterfly plot to compare nominal variables. I used the eval function in GTL to keep values related to a specific filter variable's modality, and then compare them to overall values.
Butterfly plot is finally clearer and easier to compare than a pie chart.
I created a macro to automate all this so that it can be reusable.
Thanks !
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.