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

Hi All

 

I am trying to make the attached graph in SAS - that is I want to make a proc gchart vbar on one dataset and a proc sqplot on another dataset  and then combine the two graphs using proc greplay, but it just doesnt look pretty - does anybody have any other ideas ?

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Hi

 

You combine the data that needs to be plotted into one data set using different varibale names, see below for an example

Capture.PNG

 

You then can use the appropriate plot statements of Proc SGPLOT that are compatible with each other, for your example they are VBARPARM and SCATTER

 

See also this blog entry http://blogs.sas.com/content/graphicallyspeaking/2013/03/09/parametric-bar-charts/ by @Jay54

 

Here is a code sample that creates two tables with the data to be plotted, they are combined and then used with Proc SGPLOT

 

proc sql;
  create table carsAggr1 as
  select
    origin
    , type
    , mean(horsePower) as avg_horsePower
  from
    sashelp.cars

  group by
    origin
    , type
  ;
quit;

proc sql;
  create table carsAggr2 as
  select
    origin as origin2    
    , count(*) / (select count(*) from sashelp.cars) as share_pct format=percent9.1
  from
    sashelp.cars

  group by
    origin
  ;
quit;

data carsAggr3;
  set carsAggr1 carsAggr2;
  *
  * fill it, so we do not get an additional legend entry
  *;
  if type = " " then do;
    type = "SUV";
  end;
run;

proc sgplot data=carsAggr3;
  vbarparm category=Origin response=avg_horsePower / group=Type name="bar";
  scatter x=origin2 y=share_pct / 
    y2axis 
    markerattrs=(symbol= squarefilled)
    name="scatter"
    datalabel
    datalabelpos=top
  ;
  keylegend "bar" "scatter" / 
    location=outside
    position=right
    noborder
  ;
  y2axis values=(0 to 1.2 by 0.2);
run;

Bruno

View solution in original post

2 REPLIES 2
BrunoMueller
SAS Super FREQ

Hi

 

You combine the data that needs to be plotted into one data set using different varibale names, see below for an example

Capture.PNG

 

You then can use the appropriate plot statements of Proc SGPLOT that are compatible with each other, for your example they are VBARPARM and SCATTER

 

See also this blog entry http://blogs.sas.com/content/graphicallyspeaking/2013/03/09/parametric-bar-charts/ by @Jay54

 

Here is a code sample that creates two tables with the data to be plotted, they are combined and then used with Proc SGPLOT

 

proc sql;
  create table carsAggr1 as
  select
    origin
    , type
    , mean(horsePower) as avg_horsePower
  from
    sashelp.cars

  group by
    origin
    , type
  ;
quit;

proc sql;
  create table carsAggr2 as
  select
    origin as origin2    
    , count(*) / (select count(*) from sashelp.cars) as share_pct format=percent9.1
  from
    sashelp.cars

  group by
    origin
  ;
quit;

data carsAggr3;
  set carsAggr1 carsAggr2;
  *
  * fill it, so we do not get an additional legend entry
  *;
  if type = " " then do;
    type = "SUV";
  end;
run;

proc sgplot data=carsAggr3;
  vbarparm category=Origin response=avg_horsePower / group=Type name="bar";
  scatter x=origin2 y=share_pct / 
    y2axis 
    markerattrs=(symbol= squarefilled)
    name="scatter"
    datalabel
    datalabelpos=top
  ;
  keylegend "bar" "scatter" / 
    location=outside
    position=right
    noborder
  ;
  y2axis values=(0 to 1.2 by 0.2);
run;

Bruno

AnetteD
Calcite | Level 5

Hi Bruno

 

Thank you very much for the help -  it worked 🙂

 

Anette

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 4316 views
  • 0 likes
  • 2 in conversation