Why this code don't generate the expected graphic (empty image)
proc sgplot data=sashelp.class tmplout="&demo./test.sas";
vbar sex;
run;
%include "&demo./test.sas";
proc sgrender data=sashelp.class template=sgplot;
run;
and generate the following warnings?
WARNING: The BarChartParm statement named 'VBAR' will not be
drawn because one or more of the required arguments
were not supplied.
WARNING: The BarChartParm statement named 'VBAR' will not be
drawn because one or more of the required arguments
were not supplied.
WARNING: The BarChartParm statement named 'VBAR' will not be
drawn because one or more of the required arguments
were not supplied.
Thanks
I first didn't understood your answer and then I got it. The code needs to look as follow.
proc sgplot data=sashelp.class tmplout="&demo./test.sas";
vbar sex;
run;
%include "&demo./test.sas";
proc sql;
create table class as
select sex, count(*) as _FREQUENCY_
from sashelp.class
group by sex;
quit;
proc sgrender data=class template=sgplot;
run;
I think it's because the template has DYNAMIC statements. Those are based on your data and the proc is passing them initially but when you use SGRENDER you need to specify those parameters explicitly.
My guess as to what's going on anyways.
@xxformat_com wrote:
Why this code don't generate the expected graphic (empty image)
proc sgplot data=sashelp.class tmplout="&demo./test.sas"; vbar sex; run; %include "&demo./test.sas"; proc sgrender data=sashelp.class template=sgplot; run;
and generate the following warnings?
WARNING: The BarChartParm statement named 'VBAR' will not be drawn because one or more of the required arguments were not supplied. WARNING: The BarChartParm statement named 'VBAR' will not be drawn because one or more of the required arguments were not supplied. WARNING: The BarChartParm statement named 'VBAR' will not be drawn because one or more of the required arguments were not supplied.
Thanks
Actually taking another look at the code, it's using _freq_ which isn't calculated. So for the graph, SAS is first calculating the data and then displaying it. That calculation step does not happen with SGRENDER so you need to precalculate your numbers to display them.
EDIT: this does work as expected and is the answer to why it doesn't work.
So, when you use VBAR SAS first processes the data to get the summaries as requested and then graphs the data. The Templateout only provides the code for graphing the data from the summaries, not the code to generate the summaries. You need to do that step yourself.
Here's a fully worked example:
proc sgplot data=sashelp.class tmplout="&path./Demo1.sas" ;
vbar sex;
run;
%include "&path./Demo1.sas";
*get your summaries;
proc freq data=sashelp.class;
table sex / out=summary (rename=count=_frequency_);
run;
*graph data;
proc sgrender data=summary template=sgplot;
run;
I first didn't understood your answer and then I got it. The code needs to look as follow.
proc sgplot data=sashelp.class tmplout="&demo./test.sas";
vbar sex;
run;
%include "&demo./test.sas";
proc sql;
create table class as
select sex, count(*) as _FREQUENCY_
from sashelp.class
group by sex;
quit;
proc sgrender data=class template=sgplot;
run;
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!
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.
Ready to level-up your skills? Choose your own adventure.