l am trying to draw a barchart that has a label on the top of each bar that is derived from a data set.
proc sgplot data=work.cohort_graph_FSA_read dattrmap=cohort_graph_FSA_read_attr noautolegend subpixel;
title "FSA/FSAA Reading" ;
vbar test_year / response=AL group=graph_test_score
attrid=AL_color
dataskin=pressed
datalabelpos=top
datalabel=graph_test_score
datalabelattrs=(color=white weight=bold size=12);
xaxis display=(noticks noline nolabel);
yaxis display=(noline noticks nolabel) grid max=5 min=0;
run;
where "graph_test_score" is some text derived from the data set "work.cohort_graph_FSA_read" such as "AL=3 (SS=320)" for one year(bar) and "AL=4 (SS=350)" for a different year(bar)
picture added to file
Some macro variables in your program are not resolved.
WARNING: Apparent symbolic reference DCPS_ID not resolved.
ERROR: Variable dcps_student_id is not on file
WORK.ELEMENTARY_PROMO_GRAPHS.
Try a simpler case like this that works. Maybe you can build from there.
data foo;
input cat $ Value Label $;
datalines;
A 10 X
B 15 Y
;
run;
proc print;run;
proc sgplot data=foo;
vbar cat / response=value group=cat datalabel=label groupdisplay=cluster
datalabelattrs=(size=12);
run;
Can't run your program without some sample data.
Is it not working? Try using GROUPDISPLAY=Cluster and remove DataLabelPos option.
I have attached a sample file.
removing datalabelpos and adding groupdisplay=cluster, did not work.
Here is the full code. ( I do not have rights on my computer to load a dataset, so I took one student's data and moved it into an excel file.)
proc import out=work.elementary_promo_graphs
datafile= "xxx\elmentary FSA graph label.xlsx"
dbms=xlsx replace;
sheet="Sheet1";
getnames=yes;
run;
/*** FSA\FSAA:read Graph ***/
data cohort_graph_FSA_read;
set work.elementary_promo_graphs;
where dcps_student_id="&DCPS_ID" and test_component_code in ('RO','UB') and school_number ne '9999';
graph_test_score=cat('AL=',strip(test_level),' (SS=',strip(put(test_score,4.)),')');
AL=input(test_level,4.);
test_name=strip(test_code)||' Read';
run;
data cohort_graph_FSA_read_attr;
set cohort_graph_FSA_read;
value=AL;
length fillcolor $8.;
id='AL_color';
if AL=1 then fillcolor='Red'; else
if AL=2 then fillcolor='Yellow'; else
if AL=3 then fillcolor='Green'; else
if AL=4 then fillcolor='Blue'; else
if AL=5 then fillcolor='Black'; else
fillcolor='White';
run;
proc sort data=work.cohort_graph_FSA_read; by test_year test_period_seq; run;
proc sql noprint;
select distinct
coalesce(count(test_score),1)
into
:RO_count
from
work.cohort_graph_FSA_read
where
test_score not in (.,0);
quit;
%let RO_count=&RO_count;
%put &RO_count;
/* Test History Section - FSA/FSAA:Read */
**ods region x=7.7cm y=8.0cm width=5.0cm height=5.0cm;
proc sgplot data=work.cohort_graph_FSA_read dattrmap=cohort_graph_FSA_read_attr noautolegend subpixel;
title "FSA/FSAA Reading" ;
vbar test_year / response=AL group=graph_test_score
attrid=AL_color
dataskin=pressed
groupdisplay=cluster
datalabel=graph_test_score
datalabelattrs=(color=white weight=bold size=12);
xaxis display=(noticks noline nolabel);
yaxis display=(noline noticks nolabel) grid max=5 min=0;
run;
Some macro variables in your program are not resolved.
WARNING: Apparent symbolic reference DCPS_ID not resolved.
ERROR: Variable dcps_student_id is not on file
WORK.ELEMENTARY_PROMO_GRAPHS.
Try a simpler case like this that works. Maybe you can build from there.
data foo;
input cat $ Value Label $;
datalines;
A 10 X
B 15 Y
;
run;
proc print;run;
proc sgplot data=foo;
vbar cat / response=value group=cat datalabel=label groupdisplay=cluster
datalabelattrs=(size=12);
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.