BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
MarieRall
Calcite | Level 5

Hi All,
I hope someone will be able to assist me. I'm trying to draw a bar graph using monthly data fromMarch2014 to Jan2024, but my x-axis minor tick values comes out all squashed.

My code is as follows:

proc sgplot data=INDIRECT_COSTS;
vline OBS_DATE / response=Indirect_Cost_Perc;
yaxis label="Indirect Cost%";
xaxis label="Observation Date" minor minorcount=10;
keylegend / noborder;
run;

Graph1.PNG

 

I've also tried the following code, but then I loose the detail:

proc sgplot data=INDIRECT_COSTS;
   vline OBS_DATE / response=Indirect_Cost_Perc;
   yaxis label="Indirect Cost%";
   xaxis label="Observation Date"  interval=month values=('01JAN2006'd to '01JUN2023'd by 120);
   keylegend / noborder;
run;

Graph2.PNG

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @MarieRall and welcome to the SAS Support Communities!

 


@MarieRall wrote:

I still have an issue if I want to create bars by date.


Here is an example plotting bars by date:

/* Create sample data for demonstration */

data have;
obs_date='01JAN2006'd;
Indirect_Cost_Perc=0.0064;
do i=1 to 208;
  sign=sign(Indirect_Cost_Perc);
  output;
  obs_date=intnx('month',obs_date,1);
  Indirect_Cost_Perc+rannor(1232176626)/1800;
end;
format obs_date date9. Ind: percent8.2;
run;

/* Create bar chart */

ods graphics / height=400 width=1300;
proc sgplot data=have;
vbarparm category=OBS_DATE response=Indirect_Cost_Perc / colormodel=(CXF2575F CXCAD5E5) colorresponse=sign;
yaxis label="Indirect Cost%";
xaxis label="Observation Date" interval=month fitpolicy=rotatethin;
keylegend / noborder;
run;

Result:

vbarparm_chart.png

Is there anything you would like to change?

View solution in original post

4 REPLIES 4
MarieRall
Calcite | Level 5

I found the solution. Instead of using "vline", I used "series" and that resolved my problem of the time series graphs. However I still have an issue if I want to create bars by date.

FreelanceReinh
Jade | Level 19

Hello @MarieRall and welcome to the SAS Support Communities!

 


@MarieRall wrote:

I still have an issue if I want to create bars by date.


Here is an example plotting bars by date:

/* Create sample data for demonstration */

data have;
obs_date='01JAN2006'd;
Indirect_Cost_Perc=0.0064;
do i=1 to 208;
  sign=sign(Indirect_Cost_Perc);
  output;
  obs_date=intnx('month',obs_date,1);
  Indirect_Cost_Perc+rannor(1232176626)/1800;
end;
format obs_date date9. Ind: percent8.2;
run;

/* Create bar chart */

ods graphics / height=400 width=1300;
proc sgplot data=have;
vbarparm category=OBS_DATE response=Indirect_Cost_Perc / colormodel=(CXF2575F CXCAD5E5) colorresponse=sign;
yaxis label="Indirect Cost%";
xaxis label="Observation Date" interval=month fitpolicy=rotatethin;
keylegend / noborder;
run;

Result:

vbarparm_chart.png

Is there anything you would like to change?

MarieRall
Calcite | Level 5
Thank you this solution works perfectly
DanH_sas
SAS Super FREQ

The key here is that a category axis for a line chart (VLINE/HLINE) or a bar chart (such as VBAR/HBAR) is "discrete" by default, even when presented with time data. However, if you just set TYPE=TIME on your XAXIS statement, the axis will treat the data as time data, and all of your time-axis options will work as expected. You can use a SERIES if your data is pre-summarized; but if it isn't, I would recommend switching back to a VLINE. If you are also overlaying a VBAR on the graph, you will want to switch it back.

 

Hope this helps!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

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
  • 4 replies
  • 391 views
  • 0 likes
  • 3 in conversation