BookmarkSubscribeRSS Feed
asimraja
Fluorite | Level 6

Hi,

 

I'm trying to generate a line-bar graph, where, on the x-axis, In the SAS Macro, drawlineGraph2, the labels on x-axis are too crowded.

I do not want to print every label values. However, when I try to skip the tick marks using "values" option in "xaxis" statement (see SAS Macro drawlineGraph3 below), I notice that the graph is smoother and has fewer bars, because the intermediate values between the ticks are not plotted. The attached file shows the two graphs by these two SAS Macro functions.

 

How do skip printing the labels on x-axis yet still don't compromise the accuracy of my graph.

 

%macro drawlineGraph2(
    x_var =,
    y_var1 =,
    y_var2 =,
    UPB =,
    title_txt =
);
proc sgplot data = refi_rates;

    vbar &x_var. / response = &upb. stat = mean nostatlabel y2axis nofill ;
    vline &x_var. / response = &y_var1. stat = mean nostatlabel ;
    vline &x_var. / response = &y_var2. stat = mean nostatlabel;
    y2axis min=0 max=50;
    title  "&title_txt.";
run;
%mend drawlineGraph2;

%drawlineGraph2(
    x_var = act_dte,
    y_var1 = fnm_std_rate,
    y_var2 = fnm_15yr,
    UPB = upb_value,
    title_txt = Comparison of rates
);


%macro drawlineGraph3(
    x_var =,
    y_var1 =,
    y_var2 =,
    UPB =,
    title_txt =
);
proc sgplot data = refi_rates;

    vbar &x_var. / response = &upb. stat = mean nostatlabel y2axis nofill ;
    vline &x_var. / response = &y_var1. stat = mean nostatlabel ;
    vline &x_var. / response = &y_var2. stat = mean nostatlabel;
    y2axis min=0 max=50;
    xaxis values = ("01JAN11"d to "01DEC17"d by Quarter);
    title  "&title_txt.";
run;
%mend drawlineGraph3;

%drawlineGraph3(
    x_var = act_dte,
    y_var1 = fnm_std_rate,
    y_var2 = fnm_15yr,
    UPB = upb_value,
    title_txt = Comparison of rates
);

2 REPLIES 2
Reeza
Super User

Try setting the axis type to date. It's one of the options in XAXIS statement.

ballardw
Super User

VBAR is a categorical type of plot. It show one bar for groups of values.

 

Is your actual data such that each bar is supposed to be the same height or is this just example data?

 

You can use a NEEDLE plot to approximate a VBAR by making the needles wider than default if desired. Then the xaxis values provide left and right limits of the data displayed and the specified ticks but the other values appear.

 

proc sgplot data=sashelp.stocks;
    needle  x=date y=close;
    xaxis values=( '01jan1988'd '01jan1994'd  '01jan2000'd '01jan2006'd );
run;

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3052 views
  • 2 likes
  • 3 in conversation