PROC GCHART data=sc.period;
BY units purchased;
HBAR Week Model;
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.
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.
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
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:
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)
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:
(Especially not typical if you wanted "Units Purchased" to be on the Y axis).