Sample 24879: Create a relative average chart
/* The purpose of this graph is to generate a relative */
/* bar chart based upon the average response within each */
/* By-group. Upward bars indicate response values greater */
/* than the average and downward bars indicate response */
/* values less than the average. */
/* Reset global statements */
goptions reset=all;
/* Specify macro debug options */
options mprint macrogen symbolgen;
/* Create sample data set ONE */
data one;
do subscore=1 to 2;
natavg=ranuni(0)*100;
do student=1 to 5;
do dept=1 to 9;
score=ranuni(0)*100;
output;
end;
end;
end;
run;
/* Sort data set ONE by DEPT variable */
proc sort data=one;
by subscore dept;
run;
/* Create data set MEANDATA, determine mean values */
proc means data=one noprint;
var score;
id natavg;
by subscore dept;
output out=meandata mean=means;
run;
/* Create data set TWO, */
/* create RELSCORE variable by subtracting national average from MEANS */
data two;
set meandata;
relscore=means-natavg;
run;
/* Create data set RANGE, */
/* determine minimum and maximum RELSCORE values */
proc means data=two min max noprint;
var relscore;
id natavg;
by subscore;
output out=range min=minscore max=maxscore;
run;
/* Create macro variables that resolve to values of SUBSCORE, */
/* create macro variables that resolve to values of NATAVG, */
/* create macro variables that resolve to start and end score */
/* values for Response axis, create macro variables that resolve */
/* to total number of major tickmarks on Response axis, */
/* create macro variable that resolves to total number of SUBSCORE values */
data test;
set range end=eof;
by subscore;
if first.subscore then count+1;
call symput('sub'||left(count),trim(left(subscore)));
call symput('nat'||left(count),trim(left(natavg)));
newmin=round(minscore-10,10);
call symput('start'||left(count),trim(left(newmin)));
newmax=round(maxscore+10,10);
call symput('finish'||left(count),trim(left(newmax)));
call symput('rep'||left(count),left(((newmax-newmin)/10)+1));
if eof then call symput('total',left(count));
run;
/* Create macro CHART */
%macro chart;
%do i=1 %to &total;
data _null_;
do actscore=&&start&i to &&finish&i by 10;
count+1;
call symput('val'||trim(left(&i))||left(count),"'"||
trim(left(put(actscore+&&nat&i,8.2)))||"'");
end;
run;
/* Create macro VALUE */
%macro value;
%do j=1 %to &&rep&i;
&&val&i&j
%end;
%mend value;
/* Specify AXIS statement assigned to vertical response axis */
axis1 order=(&&start&i to &&finish&i by 10) value=(%value) label=('Score');
/* Specify AXIS statement assigned to horizontal midpoint axis */
axis2 value=(a=0 r=0);
/* Specify TITLE statement */
title1 h=2.5 'Relative Average Chart';
/* Generate GCHART */
proc gchart data=two;
vbar dept / discrete sumvar=relscore
raxis=axis1 maxis=axis2 patternid=midpoint;
format relscore 5.2;
where subscore=&&sub&i;
run;
%end;
quit;
%mend chart;
/* Invoke macro CHART */
%chart

The purpose of this graph is to generate a relative
bar chart based upon the average response within each
By-group. Upward bars indicate response values greater
than the average and downward bars indicate response
values less than the average.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GCHART Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Statistical Graph Enhancements
|
| Date Modified: | 2005-08-24 16:06:28 |
| Date Created: | 2004-11-11 11:07:54 |
Operating System and Release Information
| SAS System | SAS/GRAPH | All | n/a | n/a |