BookmarkSubscribeRSS Feed
kccamillion
Calcite | Level 5

I am trying to create a comparative histogram with separate labels on each graph. I included the code I am using below. The first block is creating the annotations and the second is the univariate procedure to create the histograms. It's separated by class and there are 2 classes.

 

Is it possible to create the labels first? If not, can you label a histogram after it has been created?

 

* Note: I changed several macros for clarity, but some formatting may have been messed up in the process. The code works fine and the label works, I just need separate labels.

 

Picture1.jpg.png

 

%ANNOMAC()
DATA ANNO;
LENGTH TEXT $100;
WHEN='A';
%SYSTEM(2, 1)
%LINE(&threshold.,0, &threshold.,100, black, 2, 1)
%LABEL(&labelposition., 90, "&thresholdlabel", black, 0, 0, 2.4, 'Albany AMT', &labelalign.)
%LABEL(&labelposition., 80, "&providerlabel", black, 0, 0, 2.1, 'Albany AMT', &labelalign.)
%ARROW (&arrowx1., &arrowy., &arrowx2., &arrowy., black, 1, 1, 90, open)
;RUN;

 


PROC UNIVARIATE DATA= sample NOPRINT;
Class model
FORMAT percent_of_Providers PERCENT8.2;
VAR percent_of_Providers;
HISTOGRAM percent_of_Providers
    /anno=ANNO NOFRAME CFILL=BWH CBARLINE=BIGB VSCALE=PERCENT HEIGHT=4 BARLABEL=PERCENT
    VAXISLABEL= &yaxislabel.
    MIDPOINTS= 5 to 100
    BY 10
    FONT="Albany AMT"
    nrows=2;

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

The documentation is clear: the annotation used in your case is a "local" annotation (i.e. it is specific to one statement) and is used "for plots produced by that statement"

 

To overlay different text, your best chance is probably to use proc greplay. This works:

proc catalog c=GSEG kill; 
run;

data ANNO;
  retain WHEN 'A' XSYS YSYS '1' X Y 80 TEXT 'Anno1' COLOR 'Red' SIZE 2;
run;
                       
proc univariate data=SASHELP.CLASS noprint;
  class SEX;
  var AGE;
  histogram AGE /anno=ANNO barlabel=percent nrows=2 name='UNIV';
run;
                            
proc gslide name='GSLIDE'; 
  note move=(80,80)pct h=2 color=green 'Anno2'; 
run;

proc greplay igout=WORK.GSEG tc=SASHELP.TEMPLT template=WHOLE nofs;
  treplay 1:UNIV 1:GSLIDE ;
run;

Capture.PNG

 

SAS Innovate 2025: Register Now

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!

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
  • 1 reply
  • 1041 views
  • 0 likes
  • 2 in conversation