BookmarkSubscribeRSS Feed
gx2144
Calcite | Level 5

I want to control the output of the proc freq using proc template and I want to change the title of the plot I output using the option. Here is the code:

proc format;
 picture pctfmt (round) other="009.9%";
run;
proc template;
 define crosstabs Base.Freq.CrossTabFreqs;
 cellvalue frequency percent RowPercent ColPercent;
 define frequency;
 format=8.;
 header="Count";
 end;
 define percent;
 format=pctfmt.;
 header="Overall %";
 end;
define RowPercent;
header="Row Pct";
format=6.2;
label="Percent of Row Frequency";
end;
define ColPercent;
header="Col Pct";
format=6.2;
label="Percent of Column Frequency";
end; 
 define header tableof;
 text "Table of " _row_label_ " by " _col_label_;
 end;
 define header rowsheader;
 text " ";
 end;
 define header colsheader;
 text " ";
 end;
 cols_header=colsheader;
 rows_header=rowsheader;
 header tableof;
 end;
 define statgraph Base.Freq.Graphics.ClusterPercentChart;
 /* more code here */
 entrytitle "Distribution of" _row_label "by" _col_label;
run;

/*compare by sex*/
/*R5*/
proc freq data = subset;
label y1p_G_GIRL  = "Gender" R5status = "R5";
title "Table of Gender by R5 status";
table y1p_G_GIRL  * R5status/nopercent chisq plots=freqplot(groupby=column twoway=cluster scale=percent);
format R5status $normal.;
format y1p_G_GIRL  sex.;
run;

gx2144_0-1611542894030.png

I want to change the variable name into Gender here using proc template, it seems that it is doable using "define statgraph Base.Freq.Graphics.xxxxxxx;", but I do not what is the plot name should I use in proc template. 

 

Looking for your reply.

5 REPLIES 5
gx2144
Calcite | Level 5
The log shows the error:
error: 856-580: This statement can only be used inside the Begingraph block
Watts
SAS Employee

You can get the template name by using

ODS TRACE ON;

(Documentation for ODS TRACE is here.) 

I think the template for your plot is Base.Freq.Graphics.StackedPercentChart. 

 

 

 

 

gx2144
Calcite | Level 5
Thank you. I used ods trace on but the log error shows:
error: 856-580: This statement can only be used inside the Begingraph block"
Reeza
Super User

Although you can technically do this, using SGPLOT seems infinitely easier. Is that an option? 

A few different examples are available here. 
https://blogs.sas.com/content/graphicallyspeaking/2016/11/27/getting-started-sgplot-part-2-vbar/

 


@gx2144 wrote:

I want to control the output of the proc freq using proc template and I want to change the title of the plot I output using the option. Here is the code:

proc format;
 picture pctfmt (round) other="009.9%";
run;
proc template;
 define crosstabs Base.Freq.CrossTabFreqs;
 cellvalue frequency percent RowPercent ColPercent;
 define frequency;
 format=8.;
 header="Count";
 end;
 define percent;
 format=pctfmt.;
 header="Overall %";
 end;
define RowPercent;
header="Row Pct";
format=6.2;
label="Percent of Row Frequency";
end;
define ColPercent;
header="Col Pct";
format=6.2;
label="Percent of Column Frequency";
end; 
 define header tableof;
 text "Table of " _row_label_ " by " _col_label_;
 end;
 define header rowsheader;
 text " ";
 end;
 define header colsheader;
 text " ";
 end;
 cols_header=colsheader;
 rows_header=rowsheader;
 header tableof;
 end;
 define statgraph Base.Freq.Graphics.ClusterPercentChart;
 /* more code here */
 entrytitle "Distribution of" _row_label "by" _col_label;
run;

/*compare by sex*/
/*R5*/
proc freq data = subset;
label y1p_G_GIRL  = "Gender" R5status = "R5";
title "Table of Gender by R5 status";
table y1p_G_GIRL  * R5status/nopercent chisq plots=freqplot(groupby=column twoway=cluster scale=percent);
format R5status $normal.;
format y1p_G_GIRL  sex.;
run;

gx2144_0-1611542894030.png

I want to change the variable name into Gender here using proc template, it seems that it is doable using "define statgraph Base.Freq.Graphics.xxxxxxx;", but I do not what is the plot name should I use in proc template. 

 

Looking for your reply.


 

gx2144
Calcite | Level 5
Sgplot is doable. I use proc freq because I can simultaneously output freq table, chart, chisq table and fisher exact table.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 2927 views
  • 0 likes
  • 3 in conversation