BookmarkSubscribeRSS Feed
Filipvdr
Pyrite | Level 9

Dear,

I have several countries on my x-axis.

On the y-axis there is the value.

I need to set a different target for each country.

For example: FRANCE: min 10: bonus: 30

                    GERMANY: min 20: bonus: 50

I have this now:

proc gchart data=final_table;
  
   vbar country / sumvar=Value raxis=axis1
               nozero anno=anno
                DISCRETE ;

run;
16 REPLIES 16
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

I answered a very similar question in this thread:

Simple answer - move to Graph Template Language.  You can then have dynamic variables in the template and specify them at run time.

The other method is to generate the code.

Filipvdr
Pyrite | Level 9

RW9, thanks for your answer.

I have created a second graph with the graph template. Now it looks like my Barchart. In my dataset i have SL, and WL. Which are 2 reference lines, but they are different for each element.

Which should i do next?

proc template;

    define statgraph barchart;

    begingraph;

      entrytitle "Average Mileage by Vehicle Type";

      layout overlay;

        barchart x=element  y=Conc /

          stat=sum orient=vertical ;

      endlayout;

      endgraph;

    end;

proc sgrender data=txrf_final_table template=barchart;

run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Should be as simple as:

proc template;

    define statgraph barchart;

    begingraph;

      entrytitle "Average Mileage by Vehicle Type";

      layout overlay;

        barchart x=element  y=Conc /

          stat=sum orient=vertical ;

  refline sl / lineattrs=(pattern=dash);

  refline wl / lineattrs=(pattern=solid);

      endlayout;

      endgraph;

    end;

run;

proc sgrender data=txrf_final_table template=barchart;

run;

If you need reference on anything graph orientated, I would recommend looking at this blog: http://blogs.sas.com/content/graphicallyspeaking/

It has examples of pretty much everything, examples given in both sgplot and GTL in most cases.

Jay54
Meteorite | Level 14

RW9 has provided the code needed for this case using GTL.  I cannot see the result since the data is not included.  The REFLINE statements are SGPLOT versions and will not work in GTL.  With GTL, you need:

   Referenceline y=sl / lineattrs=(pattern=solid);

One reason to use GTL in this case would be the TARGET option.  See documentation.

Alternatively, you can also use SGPLOT procedure to do the same.  I used sashelp.cars to see some results. 

Refline values can be numbers, macro variables or columns in the data.

title  "Average Mileage by Vehicle Type";

proc sgplot data=sashelp.cars;

vbar type / response=mpg_city stat=mean;

refline 10 / lineattrs=(pattern=dash);

refline 20 / lineattrs=(pattern=solid);

run;

Filipvdr
Pyrite | Level 9

Thanks for your answers but this is not what I need.

I need to draw a small line on each bar , one SL, one WL. The SL and WL is different for each BAR! Actually it is more lixe a boxplot, but without the boxes? Smiley Happy

Jay54
Meteorite | Level 14

In that case, you need to overlay two statements, one to draw the bar, one to draw the target.

Which version of SAS are you using (with maintenance level)?  Do you have SAS 9.3 or higher?

Filipvdr
Pyrite | Level 9

We have SAS 9.2

For Base Product ...

   Custom version information: 9.21_M3

For SAS/STAT ...

   Custom version information: 9.22

For SAS/GRAPH ...

   Custom version information: 9.21_M2

Jay54
Meteorite | Level 14

You have less options with SAS 9.2, and may need to use GTL as suggested by RW9.  I would use an overlay of bars and scatter.

To get a line over the bar, you may need some more code.  Easier with SAS 9.3 or later.  🙂

proc means data=sashelp.cars;

  class type;

  var mpg_city mpg_highway;

  output out=cars(where=(_type_ > 0))

    mean (mpg_city mpg_highway)=city highway;

run;

proc template;

  define statgraph bars;

    begingraph;

      entrytitle  "Average Mileage by Vehicle Type";;

      layout overlay / yaxisopts=(offsetmin=0);

        barchart x=type y=city / name='a';

        scatterplot x=type y=highway / name='b';

        discretelegend 'a' 'b';

   endlayout;

  endgraph;

  end;

run;

proc sgrender data=cars template=bars;

run;

Filipvdr
Pyrite | Level 9

thanks Sanjay, this is already more the way they want it to be. I will look further now to customize and change the icons.

Jay54
Meteorite | Level 14

Time to upgrade.  Smiley Happy  Anything higher than SAS 9.2 will provide you more options, including annotation.

I came into this thread a bit late because I figured GCHART with annotate would be the right solution, especially with SAS 9.2. 

Why did that not work?   

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Just from my side here, I would do this kind of thing for normal ranges.  First I would take a distinct list and in that dataset have the higher lower for each parameter as this will differ.  From that dataset I then generate the code:

data refs;

     param="ABC"; higher=23; lower=4; output;

     param="DEF"; higher=12; lower=8; output;

run;

proc template;

     ...

     dynamic _h _l;

     ...

     Referenceline y=_h / lineattrs=(pattern=solid) name="UpperRange";

     Referenceline y=_l / lineattrs=(pattern=solid) name="LowerRange";

...

run;

data _null_;

     set refs;

     call execute(cats('proc sgrender data=have (where=(param="',param,'")) template=...; dynamic _h=',put(higher,best.),' _l=',put(lower,best.),'; run;');

run;

In this way the sgrender is called once per parameter and the dynamic variable is set to the respective range.

Filipvdr
Pyrite | Level 9

Yes, but the reference line can NOT be drawn over the whole graph. Only on the bar where it should be.

Filipvdr
Pyrite | Level 9

Hello all: i got this now:

proc template;

  define statgraph barchart;

    begingraph;

      entrytitle  "&wafersource_list";

      layout overlay /

  yaxisopts=(offsetmin=0

             label="Conc (E10A/cm2)"

  tickstyle=across);

        barchart x=element y=Conc / name='a'  fillattrs=(color=cxFFFF66)  ;

        scatterplot x=element y=WL / name='b' markerattrs=(symbol=HomeDown);

        scatterplot x=element y=SL / name='c' markerattrs=(symbol=HomeDownFilled);

        discretelegend 'a' 'b' 'c';

   endlayout;

  endgraph;

  end;

run;

What i would like to now is:

1: remove the border around the graph

2: put more ticks on the y ax

any ideas?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, to remove the border it should be as straightforward as:

ods graphics / reset=all height=15cm width=19cm noborder;

For more tickaxis values:

yaxisopts=(offsetmin=0 label="Conc (E10A/cm2)" tickstyle=across tickvaluesequence=(start=0 end=100 increment=10));

                                                                                                                                         ^         ^                     ^

Change these to your ranges.  You could also put a list in there and specify exactly what ticks you want.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 16 replies
  • 3213 views
  • 6 likes
  • 4 in conversation