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

Hi,

I would like to graph a frequency distributions chart to compare the distribution of manipulator and non-manipulator.

 

However, the frequency of manipulator is really small, so i want to multiply a number on the frequency of distrubution for manipulator in order to allow easier visual comparison with the much larger sample of non-manipulator.

 

I use proc sgplot. How can I make it work?

 

Thank you very much for your help.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

If you want a kernel density estimate of the FREQ variable, you can use 

proc sgplot data=em;
density freq / type=kernel group=em;
run;

If you want to form a histogram, but plot the frequencies as a series, you can use PROC UNIVARIATE to bin the data and the SERIES statement to plot the binned frequencies:

 

proc univariate data=em noprint;
class em;
histogram freq  / outhist=out
            midpoints=(0 to 0.8 by 0.05);
run;

proc sgplot data=out;
series x=_midpt_  y=_count_ / group=em;
run;

View solution in original post

9 REPLIES 9
Rick_SAS
SAS Super FREQ

Instead of multiplying, plot both histograms or bar charts on the percentage scale. For example, this is how you can plot percentage of males and females on the same bar chart:

 

proc sgplot data=sashelp.class;
vbar age / group=sex stat=percent groupdisplay=cluster;
run;

If you have a continuous variable, you can use  comparative histograms to compare the distribution across groups.

Terrencefung
Calcite | Level 5
Thank you very much for your prompt response. But it has to be the frequency scale. D you know how to do it? thank you
Rick_SAS
SAS Super FREQ

I don't understand why you say "it has to be the frequency scale."  To compare absolute counts, plot the data on the count scale. To compare the relative proportions, plot on the percentage scale.

 

Do you have some sampling scheme in which you oversampled one category? For example, does each male in your data represent 10 members of the population but each female represents 100?  Even then, I think plotting proportions are the way to go.

Terrencefung
Calcite | Level 5

Hi Rick,

 

Sorry for making you confuse.
I have matched one manipulator to five non-manipulator, and i need to graph a frequency distribution char to compare the difference of ditribution between manipulator and non-manipulator.

 

Please find the attached figure. I need to do the same thing as the enclosed figure.

 

Thank you very much for your help.


figure.jpg
Rick_SAS
SAS Super FREQ

Well, I still don't like it, but you can do it by using a FREQ variable. Here is an example in which each female in the data set  represents 5 females:

 

data FakeData;
set sashelp.class;
if sex="F" then freq=5;
else freq=1;
run;

proc sgplot data=FakeData;
vbar age / group=sex freq=freq groupdisplay=cluster;
run;
Terrencefung
Calcite | Level 5

Thank you for your help, though it is still different from what i need.

 

Regards,

Rick_SAS
SAS Super FREQ

If you want a line instead of bars, just use the VLINE statement instead of VBAR.

 

If you have a continuous variable, use the DENSITY statement.

 

If you post some sample data, I'm sure that someone can give you what you need.

 

 

Terrencefung
Calcite | Level 5

Thank you. the following is the sample data. i want to compare the difference of  distribution (frequency) of Estimated probability between em=1 and em=0.

 

Global CompanyData Year -emEstimated Probability
KeyFiscal
  
  
1173199910.50883
137377199900.53093
1173199910.50883
31015199900.36718
1173199910.50883
8388199900.45892
1173199910.50883
133729199900.52904
1173199910.50883
61553199900.6904
1173200010.48688
63038200000.53392
1173200010.48688
26038200000.67335
1173200010.48688
15758200000.56561
1173200010.48688
62874200000.49828
1173200010.48688
143526200000.48667
1173200110.48896
15758200100.43567
1173200110.48896
2299200100.4265
1173200110.48896
24982200100.52106
1173200110.48896
Rick_SAS
SAS Super FREQ

If you want a kernel density estimate of the FREQ variable, you can use 

proc sgplot data=em;
density freq / type=kernel group=em;
run;

If you want to form a histogram, but plot the frequencies as a series, you can use PROC UNIVARIATE to bin the data and the SERIES statement to plot the binned frequencies:

 

proc univariate data=em noprint;
class em;
histogram freq  / outhist=out
            midpoints=(0 to 0.8 by 0.05);
run;

proc sgplot data=out;
series x=_midpt_  y=_count_ / group=em;
run;

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
  • 9 replies
  • 8153 views
  • 0 likes
  • 2 in conversation