Hi folks,
In this swimmer's plot, I'd like to show "dose levels" and "short texts" indicating histology of tumors inside the bars. Desirable image is shown below that I manually created in photoshop.
Dataset and initial proc sgplot is following. Can you please help add these details to the plot?
DATA SWIMMER1;
infile datalines dsd;
informat TRTCAP $12.;
INPUT SUBJID $ TRTSTDY TRTENDY ORDER TRTCAP $ DOSE_LEVEL $ TUMOR_HISTOLOGY $;
DATALINES;
24,1,28,1,,DL-2,TEXT1
29,1,28,2,,DL-2,TEXT2
20,1,28,3,,DL-2,TEXT3
21,1,29,4,,DL-2,TEXT3
19,1,70,5,,DL-2,TEXT3
22,1,91,6,,DL-2,TEXT3
25,1,91,7,FilledArrow,DL-2,TEXT3
27,1,91,8,FilledArrow,DL-2,TEXT3
10,1,117,9,,DL-2,TEXT3
;
PROC PRINT; RUN;
PROC SGPLOT DATA=SWIMMER1;
HIGHLOW Y=ORDER LOW=TRTSTDY HIGH=TRTENDY / LOWLABEL=SUBJID TYPE=BAR
HIGHCAP=TRTCAP;
XAXIS LABEL='Study Day' VALUES=(0 TO 120 BY 30);
YAXIS LABEL='Subject ID' DISPLAY=(NOTICKS NOVALUES);
RUN;
Thank you for your time in advance.
If you want to display text on many plots then a TEXT plot is the starting point.
PROC SGPLOT DATA=SWIMMER1; HIGHLOW Y=ORDER LOW=TRTSTDY HIGH=TRTENDY / LOWLABEL=SUBJID TYPE=BAR HIGHCAP=TRTCAP name='hl'; text x=TRTENDY y=order text=TUMOR_HISTOLOGY / position=left /*places text just left of coordinate*/ ; XAXIS LABEL='Study Day' VALUES=(0 TO 120 BY 30); YAXIS LABEL='Subject ID' DISPLAY=(NOTICKS NOVALUES); keylegend 'hl'; RUN;
You may want to provide a different horizontal coordinate variable if the values are too close to the end of the bar or you want to move them from the arrow portions.
If you want to display text on many plots then a TEXT plot is the starting point.
PROC SGPLOT DATA=SWIMMER1; HIGHLOW Y=ORDER LOW=TRTSTDY HIGH=TRTENDY / LOWLABEL=SUBJID TYPE=BAR HIGHCAP=TRTCAP name='hl'; text x=TRTENDY y=order text=TUMOR_HISTOLOGY / position=left /*places text just left of coordinate*/ ; XAXIS LABEL='Study Day' VALUES=(0 TO 120 BY 30); YAXIS LABEL='Subject ID' DISPLAY=(NOTICKS NOVALUES); keylegend 'hl'; RUN;
You may want to provide a different horizontal coordinate variable if the values are too close to the end of the bar or you want to move them from the arrow portions.
@Cruise wrote:
@ballardw thank you so much. Do you have any suggestions how to place Dose Levels in the beginning of each bar?
You would provide an x coordinate for the LOW end of your highlow ploat and use the Position=Right so the text appears right of that coordinate:
PROC SGPLOT DATA=SWIMMER1; HIGHLOW Y=ORDER LOW=TRTSTDY HIGH=TRTENDY / LOWLABEL=SUBJID TYPE=BAR HIGHCAP=TRTCAP; text x=trtstdy y=order text=TUMOR_HISTOLOGY / position=right; XAXIS LABEL='Study Day' VALUES=(0 TO 120 BY 30); YAXIS LABEL='Subject ID' DISPLAY=(NOTICKS NOVALUES); RUN;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.