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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 794 views
  • 0 likes
  • 2 in conversation