Hi i am a student,
I am very new to sas and am working on hotel demand dataset, I want to show the maximum booking month by counting the values of arrival_date_month which is a variable in my dataset. I tried it but i am not getting what i want. I want to sort the order of variables inside a bar chart,please help!
I have used this code:
axis label=(h=10pt font='Arial/bo');
axis label=(h=10pt font='Arial/bo' angle=90);
ods listing;
proc gchart data=hotel.main1;
title 'Highest booking month';
vbar arrival_date_month / type=sum
patternid=midpoint
maxis=axis1
raxis=axis2;
label arrival_date_month='count';
run;
quit;
Could you please help where i am wrong in the code? Please let me know i can explain better my question .
Thanks in advance.
Amali
What variables inside a bar chart? You don't say what that variable would be.
I would also suggest moving to Proc SGPLOT instead. There isn't any development going on with the older Gchart and Gplot procedures.
Maybe something along these lines:
proc sgplot data=hotel.main1; vbar arrival_date_month /response=<some variable name to sum> stat=sum group=<variable to indicate groups> groupdisplay=stack grouporder= data ; label arrival_date_month='count'; run;
creates on bar for each value of arrival_date_month;
the variable after RESPONSE is what would be summed to get the size of the value block
Group would be any variable indicating a group of related records maybe "hotel" since your topic may involve hotels, or a variable that holds a geographic indicator.
Groupdisplay can be Stack (one bar) or Cluster which would have each group value as a separate bar within the month . The grouporder indicates which order to arrange the groups, data use the value of the statistic.
The Xaxis and Yaxis statement in the procedure provide options but the syntax is different than the AXIS statements.
What variables inside a bar chart? You don't say what that variable would be.
I would also suggest moving to Proc SGPLOT instead. There isn't any development going on with the older Gchart and Gplot procedures.
Maybe something along these lines:
proc sgplot data=hotel.main1; vbar arrival_date_month /response=<some variable name to sum> stat=sum group=<variable to indicate groups> groupdisplay=stack grouporder= data ; label arrival_date_month='count'; run;
creates on bar for each value of arrival_date_month;
the variable after RESPONSE is what would be summed to get the size of the value block
Group would be any variable indicating a group of related records maybe "hotel" since your topic may involve hotels, or a variable that holds a geographic indicator.
Groupdisplay can be Stack (one bar) or Cluster which would have each group value as a separate bar within the month . The grouporder indicates which order to arrange the groups, data use the value of the statistic.
The Xaxis and Yaxis statement in the procedure provide options but the syntax is different than the AXIS statements.
I got this output for the barchart code which i posted, here in y axis i would like to sort the months from jan to december. Could you help how to sort the months in my coding ?
If you want values to sort then use values that sort properly. In this case I would suggest going back to your data and doing one of two things:
1) Create a date valued variable instead of text with values like 'Jan' with a format of MONNAME3.
2) Create a numeric variable with values of 1 to 12 and assign a custom format that will display 1 as Jan, 2 as Feb and so on.
Of these two I strongly recommend learning to use DATE values as they are very flexible and there are many tools to manipulate or display values.
If you do not have an actual date value this is one way to get it from what appears to be in your data:
data want; set hotel.main1; y= input(cats('01',substr(arrival_date_month,1,3),'2020'),date9.); format y monname3.; run;
Use Y, or what ever variable you create, instead of arrival_date_month.
Or if you already have a full date variable use that but apply a MONNAME3. (or 4) format.
The above code uses a fixed year because I really don't know your data. If you have a numeric year you could use that variable instead of '2020'. Even when dates are across years the formatted value should be used to create the groups.
If you want to do it with gchart, here's a short example showing how ... Note that I use a numeric date value (which controls the order of the bars), and I apply the monname3. format (which prints the numeric date as the 3-character text month name). Also note that I use the 'discrete' option (otherwise gchart might group bars together like a histogram).
data foo; set sashelp.stocks (where=(stock='IBM' and year(date)=2004));
run;
title "IBM Stock Price in 2004";
axis1 label=none minor=none;
proc gchart data=foo;
format date monname3.;
vbar date / discrete type=mean sumvar=close raxis=axis1 maxis=axis1;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: