BookmarkSubscribeRSS Feed
deleted_user
Not applicable
hello All,

I use the code :-

PROC GCHART data=sc.period;
BY units purchased;
HBAR Week Model;
RUN;

My objective is to produce a Bar Chart that will give me the number of units purchased in 4 weeks ( the varibale Week is a character variable and has 4 categories - Week1 ,...,Week4).I want that this char give me the number of units purchased in each week , so that Week is one the x-axis and Units Purchased on y-axis.

Secondly, supoose that the variable Model has 3 categories ( Model 1, Model2 and Modle 3).Then in that case what should I use in the code as my final aim is to produce Bar chart or Histogram that will tell me the number purchased in each week for each Model.

Kind Regards,
Mark
7 REPLIES 7
Tim_SAS
Barite | Level 11
There's an entire forum dedicated to SAS/GRAPH questions, just a few rows down from this one. On the main forums page, look for SAS/GRAPH and ODS Graphics. Try your question there. Good luck!
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Comment to OP: the post content of MC appears mysteriously similar to that of MarkC.

Honestly, as has been recommended with your prior posts, it's not going to help you get SAS programming assistance when you are unwilling to embrace SAS documentation and supplemental technical reference material available to you at SAS.COM.

Scott Barry
SBBWorks, Inc.
Flip
Fluorite | Level 6
Scott;

Do you expect him to do his own home work. Come on!
RickM
Fluorite | Level 6
So now you need 2 accounts on here as well as 3 or 4 on SAS-L? Too many people stop giving you fully coded answers to your homework?

Seriously, the second anyone (employer/teacher) asks you even the most basic question about SAS you will have no clue what the answer is unless you actually start putting some effort into learning instead of trying to find ways to just get the answers to the questions. Message was edited by: RickM
Flip
Fluorite | Level 6
If this class has a final exam, Mark is in trouble.
Cynthia_sas
SAS Super FREQ
There is no better guide to SAS/GRAPH than the examples contained in the award-winning SAS/GRAPH documentation:
http://support.sas.com/documentation/cdl/en/graphref/61884/HTML/default/gchart-bar.htm
http://support.sas.com/documentation/cdl/en/graphref/61884/HTML/default/gr13n07-ex.htm
http://support.sas.com/documentation/cdl/en/graphref/61884/HTML/default/gr13n03-ex.htm

And the SAS Notes:
http://support.sas.com/kb/24/870.html

And this is a good paper:
http://analytics.ncsu.edu/sesug/2004/TU02-Cochran.pdf

If UNITS and PURCHASED are numeric variables, you would not typically use them as BY group variables for graphing purposes. Especially since you said you wanted to have Units Purchased on the Y axis -- this makes me wonder whether you have 1 variable with a label of "Units Purchased" -- but -- the way you have your BY statement coded, it looks like there are 2 numeric variables called UNITS and PURCHASED that are being used as BY group variables (instead of 1 variable).

Generally, you do not refer to a variable LABEL (such as "Units Purchased" in any SAS statement, you refer to the variable NAME. So if the variable name is UNITSSOLD, it might have a label of "Units Sold"; or if the variable name is UNITSPURCHASED, it might have a label of "Units Purchased". One of the fundamental concepts of SAS variable names is that the variable name cannot contain spaces or any character other than an underscore (_). To refer to a variable any other way, you must use a different naming convention. As explained in the documentation:
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000998953.htm

In the documentation for the HBAR statement, you will want to pay particular attention to the SUMVAR= option and the GROUP= option for the HBAR statement. There are many examples that show the use of these options with PROC GCHART. (Also, you might want to investigate the differences between an HBAR chart and a VBAR chart, especially if you want "Units Purchased" on the Y axis.)

In addition, BY group processing is often used in the creation of SAS/GRAPH output when you want the same graph image created for every BY group category, such as:
[pre]
by country; (one graph for each country value)
by type; (one graph for each type value)
by country type; (one graph for every unique combo of country and type values)
etc.
[/pre]

So, aside from issues of using the variable NAME, instead of the variable LABEL, it would still not be typical usage to have a BY statement with:
[pre]
by unitssold;
by unitsspurchased;
[/pre]

(Especially not typical if you wanted "Units Purchased" to be on the Y axis).

So, I would also suggest that you also read this documentation on BY group processing concepts:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a000060410.htm

cynthia
Jay
Calcite | Level 5 Jay
Calcite | Level 5
Cynthia,

I admire your patience. Your's goes way beyond merely serving your customer. (As noted, maybe in this case it involves doing their homework for them 😉

People like you do in fact make this a better world.

I "tip my hat to you"!

Jay

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 1018 views
  • 0 likes
  • 7 in conversation