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

Hello,

on the same excel page, below the proc report, I want to insert two graphs in two columns.

I miss an option like columns = 2 for this two graphs.

Could you help me please.

data men(rename=(name=name_m age=age_m sex=sex_m Weight=Weight_m height=height_m));

do i=1 to 10;
set sashelp.class(where=(sex='M'));
i=i;
output;
end;

run;

data women(rename=(name=name_f age=age_f sex=sex_f Weight=Weight_f height=height_f));
do i=1 to 10;
set sashelp.class(where=(sex='F') );
i=i;
output;
end;
run;

data reg;
merge  men women;by i;
col_vide='';
run;


ods _all_ close;

ods excel file="H:\Report.xlsx" options(sheet_interval="none");
proc report data =reg;
col('Men' name_m age_m sex_m Weight_m height_m) col_vide
('Women' name_f age_f sex_f Weight_f height_f);

run;


goptions device=png ;

proc gchart data=reg;
   vbar age_m ;
run; quit;

proc gchart data=reg;
   vbar age_f ;
run; quit;


ods excel close;

ODS LISTING CLOSE;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You need to reconsider your data structure for this graph. 

Try this:

 

proc sort data=sashelp.class out=class; by sex;
run;
proc sgpanel data=class ;
panelby  sex /columns=2;
vbar age;
run;

I suspect you could also do that for PROC REPORT and not have to split up your data but I'm not 100% sure of that. 

View solution in original post

9 REPLIES 9
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Stop using the ancient gplot functions.  Look at modern programming functions like sgplot, or in your case: sgpanel:

http://support.sas.com/documentation/cdl/en/grstatproc/62603/HTML/default/viewer.htm#sgpanel-concept...

mansour_ib_sas
Pyrite | Level 9

thank you for your answer,

ideally I try to do like this.

can we set the columns option at the beginning?

 

ods _all_ close;

ods excel file="H:\Report3.xlsx" options(sheet_interval="none");

proc report data =reg;
col('Men' name_m age_m sex_m Weight_m height_m) col_vide
('Women' name_f age_f sex_f Weight_f height_f);

run;


proc sgpanel data= reg;
panelby  sex_f /columns=1;

vbar age_f;


panelby  sex_m /columns=2 ;
vbar age_m;

run;
ods excel close;

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I am sorry, I do not understand what you mean.  You set parameters where they are expected?

Jay54
Meteorite | Level 14

You can only have one PANELBY in one procedure step.  It will automatically produce the number of cells needed based on the number of unique class values.  Please review the doc for PROC SGPANEL, or see many examples here: https://blogs.sas.com/content/graphicallyspeaking/?s=sgpanel

 

mansour_ib_sas
Pyrite | Level 9

Error Log:

ERROR: The same category variable must be used for summarized plots.

 

 

 

 




data men(rename=(name=name_m age=age_m sex=sex_m Weight=Weight_m height=height_m)); do i=1 to 10; set sashelp.class(where=(sex='M')); i=i; output; end; run; data women(rename=(name=name_f age=age_f sex=sex_f Weight=Weight_f height=height_f)); do i=1 to 10; set sashelp.class(where=(sex='F') ); i=i; output; end; run; data reg; merge men women;by i; col_vide=''; run; ods _all_ close; ods excel file="H:\Report3.xlsx" options(sheet_interval="none"); proc report data =reg; col('Men' name_m age_m sex_m Weight_m height_m) col_vide ('Women' name_f age_f sex_f Weight_f height_f); run; proc sgpanel data= reg; panelby sex_f sex_m/columns=2; title "Yearly Sales by Product"; vbar age_f; title "Yearly Sales by Product"; vbar age_m; run; ods excel close;
DanH_sas
SAS Super FREQ

Your SGPANEL code should look like this:

 

title "Yearly Sales by Product";
proc sgpanel data= sashelp.class;
panelby  sex / columns=2 novarname;
  vbar age;
run;
Reeza
Super User

You need to reconsider your data structure for this graph. 

Try this:

 

proc sort data=sashelp.class out=class; by sex;
run;
proc sgpanel data=class ;
panelby  sex /columns=2;
vbar age;
run;

I suspect you could also do that for PROC REPORT and not have to split up your data but I'm not 100% sure of that. 

mansour_ib_sas
Pyrite | Level 9

I thought about this option. 

I consider that the subject is closed

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 833 views
  • 0 likes
  • 5 in conversation