help with basic graphs in SAS

#1
I've been searching for a few hours but still can't figure out how to create a basic bar chart in SAS.

For example, my data looks has 3 columns: Year, State, Company, and sales.

Suppose I just want to create a basic bar chart to compare sales of different states in one graph, how would I do it? and what is the difference between plot, gchart, gplot etc etc? There's quite a few that I do not know when to use what.

My code:
Proc gchart data=work.nbcounts;
vbar sales/ type=sum group=State;
run;

I tried I with and without the group statement, but that didn't work. I tried by state;, but that did not work either.

what I"M getting is I'm getting the sales numbers at the x axis, and the frequency of that number, which is not what I want. All I'm wanting is sum of total sales by state. So state on the x-axis, and sales on the Y.
 
Last edited:

Stu

New Member
#2
It can be quite complicated to grapple with all of the charting options in SAS. Graphing is one of SAS's very first features, and it has been updated numerous times throughout its life.

PROC PLOT - 1st version of plotting procedure.
PROC GPLOT - 2nd plotting procedure.
PROC SGPLOT - Most recent plotting procedure.

I recommend using PROC SGPLOT. It's very versatile and relatively intuitive. To use SGPLOT for comparing sales of different states in one graph, you'd do the following:

Code:
data states;
	do state = 'Alabama', 'Georgia', 'New York';
		do i = 1 to 1000;
			sale = rand('uniform')*100;
			output;
		end;
	end;
run;

proc sgplot data=states;
	vbar state / group=state response=sale stat=sum;
run;
The reason why GPLOT is not working for you is because the VBAR statement is expecting a category, not a response. The option RESPONSE allows you to set your y. I made the same mistake :) Note that the GROUP= option allows SGPLOT to apply different visual elements; otherwise, they are all the same color.
 
Last edited: