BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
majdi_ka
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
pearsoninst
Pyrite | Level 9
I think you should use butterfly chat , that is mush better .Just give a search ..There is a great artical on this.

View solution in original post

10 REPLIES 10
pearsoninst
Pyrite | Level 9
Pls give an example Chart what you are looking for and sample data.
Jay54
Meteorite | Level 14

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;

 

majdi_ka
Obsidian | Level 7

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

 

pearsoninst
Pyrite | Level 9
I think you should use butterfly chat , that is mush better .Just give a search ..There is a great artical on this.
majdi_ka
Obsidian | Level 7

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. 

 

DanH_sas
SAS Super FREQ

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

Jay54
Meteorite | Level 14

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.

majdi_ka
Obsidian | Level 7

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 !

pearsoninst
Pyrite | Level 9
Great Job majdi_ka .. Keep it up and all the best ...

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1615 views
  • 5 likes
  • 4 in conversation