Help using Base SAS procedures

Suggestion for a good paper on the topic

Posts: 0

Suggestion for a good paper on the topic

hello All,

I use the code :-

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.

Kind Regards,
Super Contributor
Posts: 394

Re: Suggestion for a good paper on the topic

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!
Super Contributor
Super Contributor
Posts: 3,174

Re: Suggestion for a good paper on the topic

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.
Super Contributor
Posts: 359

Re: Suggestion for a good paper on the topic


Do you expect him to do his own home work. Come on!
Regular Contributor
Posts: 165

Re: Suggestion for a good paper on the topic

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
Super Contributor
Posts: 359

Re: Suggestion for a good paper on the topic

If this class has a final exam, Mark is in trouble.
Posts: 8,744

Re: Suggestion for a good paper on the topic

There is no better guide to SAS/GRAPH than the examples contained in the award-winning SAS/GRAPH documentation:

And the SAS Notes:

And this is a good paper:

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:

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:
by unitssold;
by unitsspurchased;

(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:

Contributor Jay
Posts: 24

Re: Suggestion for a good paper on the topic


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 Smiley Wink

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

I "tip my hat to you"!

Ask a Question
Discussion stats
  • 7 replies
  • 7 in conversation