BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Anita_n
Pyrite | Level 9

Dear all, 

I have this code to label the bar segments  in the chart usings the text statement. My problem is this cannot be probably centered and fit also not properly in the segments. I had to delete some data to avoid congestion (where number of cases < 6). Is there any better way to do this?

 

data mydat;
	infile datalines;
	input year Therapy $15. group_T number_of_cases;
	datalines;
2020 CB_Ara	         1 2
2020 Transplantation 1 87
2020 Operation	     1 30
2020 Transfusion	 1 63
2020 Radiotherapy	 1 18
2020 Chemotherapy	 1 1
2021 Oral_PR	     1 1
2021 CB_Ara	         1 4
2021 Transplantation 1 52
2021 Operation	     1 16
2021 Transfusion	 1 41
2021 Radiotherapy	 1 5
2021 Chemotherapy	 1 3
2022 CB_Ara	         1 8
2022 Transplantation 1 69
2022 PreSur	         1 3
2022 Operation	     1 30
2022 W&W	         1 1
2022 Transfusion	 1 31
2022 Radiotherapy	 1 25
2022 Chemotherapy	 1 3
2020 Oral_PR	     2 4
2020 CB_Ara	         2 6
2020 Transplantation 2 21
2020 PreSur	         2 4
2020 Operation	     2 33
2020 Transfusion	 2 9
2020 Antibodytherapy 2 1
2020 Radiotherapy	 2 8
2020 Chemotherapy	 2 2
2020 Injectibles	 2 5
2021 Oral_PR	     2 3
2021 CB_Ara	         2 3
2021 Transplantation 2 8
2021 PreSur	         2 12
2021 Operation	     2 11
2021 TM-GH	         2 1
2021 Transfusion	 2 3
2021 adjuvant	     2 1
2021 Radiotherapy	 2 6
2021 abortive	     2 2
2021 Injectibles	 2 1
2022 Oral_PR	     2 2
2022 CB_Ara	         2 2
2022 Transplantation 2 7
2022 PreSur	         2 44
2022 Operation	     2 6
2022 W&W	         2 1
2022 TM-GH	         2 6
2022 Transfusion	 2 1
2022 Radiotherapy	 2 10
2022 abortive	     2 2
2022 Chemotherapy	 2 1
2020 Oral_PR	     3 1
2020 CB_Ara	         3 2
2020 Transplantation 3 4
2020 PreSur	         3 8
2020 Operation	     3 12
2020 W&W	         3 1
2020 Transfusion	 3 2
2020 Radiotherapy	 3 5
2020 abortive	     3 1
2020 Radiation	     3 1
2020 Chemotherapy	 3 3
2020 Injectibles	 3 6
2021 Oral_PR	     3 1
2021 CB_Ara	         3 3
2021 Transplantation 3 2
2021 PreSur	         3 11
2021 Operation	     3 4
2021 Transfusion	 3 1
2021 adjuvant	     3 1
2021 Radiotherapy	 3 1
2021 abortive	     3 2
2022 Oral_PR	     3 2
2022 CB_Ara	         3 4
2022 PreSur	         3 16
2022 Operation	     3 10
2022 W&W	         3 2
2022 TM-GH	         3 23
2022 Transfusion	 3 2
2022 adjuvant	     3 3
2022 Antibodytherapy 3 1
2022 Radiotherapy	 3 7
2022 abortive	     3 2
2020 Oral_PR	     4 1
2020 CB_Ara	         4 5
2020 PreSur	         4 4
2020 Operation	     4 10
2020 Radiotherapy	 4 4
2020 abortive	     4 1
2020 Chemotherapy	 4 2
2021 Transplantation 4 1
2021 PreSur	         4 9
2021 adjuvant	     4 2
2021 Radiotherapy	 4 3
2022 Oral_PR	     4 1
2022 PreSur	         4 7
2022 Operation	     4 4
2022 W&W	         4 1
2022 TM-GH	         4 16
2022 adjuvant	     4 7
2022 Radiotherapy	 4 5
2022 abortive	     4 3
2020 Oral_PR	     5 3
2020 CB_Ara	         5 1
2020 PreSur	         5 4
2020 Operation	     5 3
2020 W&W	         5 1
2020 adjuvant	     5 2
2020 Radiotherapy	 5 3
2020 abortive	     5 1
2020 Chemotherapy	 5 1
2021 W&W	         5 1
2021 TM-GH	         5 2
2021 Transfusion	 5 1
2021 adjuvant	     5 1
2021 Radiotherapy	 5 3
2021 abortive	     5 3
2021 Radiation	     5 1
2021 Chemotherapy	 5 2
2021 Injectibles	 5 1
2022 CB_Ara	         5 3
2022 Transplantation 5 1
2022 PreSur	         5 3
2022 Operation	     5 3
2022 TM-GH	         5 17
2022 adjuvant	     5 5
2022 Antibodytherapy 5 1
2022 Radiotherapy	 5 4
2022 abortive	     5 8
2022 Injectibles	 5 1
;
run;

proc sql;

create table sumdat as select year, group_T, sum(number_of_cases) as total  from mydat  group by group_T, year;

create table cal_percent as select a.*, b.total,  number_of_cases/total as percentage format percent6.0 from mydat as a, sumdat as b
where a.group_T=b.group_T and a.year=b.year;
quit;

proc sort data=cal_percent;
by year group_T;
run;

data have;
set cal_percent;
by year group_T;

length N_plus_Percent $15 ;

N_plus_Percent=catx(" ", number_of_cases, "*", put(percentage, percent6.0));

if first.group_T then td=0;
pos= td + number_of_cases/2;
td + number_of_cases;

if last.group_T then 
  do;
    overall=total;
   end;

if number_of_cases < 6 then N_plus_Percent="";

run;

ods pdf;
proc sgpanel data=have pad=(bottom=5%) dattrmap= abg.attrmap_pri_endpoints noautolegend ;

panelby  year/ columns=3 novarname noborder headerattrs=(color=dimgray family=arial weight=bold size=7pt) 
nowall sort=data ;

vbarparm category=group_T response=overall/ datalabel=overall outline outlineattrs=(color=white thickness=1) nofill name='a';

vbarparm  category=group_T response=number_of_cases / group=therapy groupdisplay=stack attrid=therapy missing grouporder=data name='b'; 

text x=group_T y=pos text=N_plus_Percent / group=therapy groupdisplay=cluster position=center splitchar="*"  splitpolicy=splitalways 
textattrs=(family=arial color=black size=5pt weight=bold);

rowaxis grid display=(nolabel) valueattrs=(size=7pt family=arial color=dimgray) values=(0 to 200 by 20) offsetmin=0 ;

colaxis  display=(nolabel) discreteorder=data  valueattrs=(size=5pt family=arial color=dimgray) valuesrotate=diagonal2;

keylegend 'b'/linelength=10 position=bottom fillheight=1.5pct title="" valueattrs=(size=0.5pt family=arial) outerpad=(top=0.2cm) noborder;
run;

ods pdf close;
1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Sorry for the noise. I analyzed this further. The main issue causing your alignment issue is having the GROUP and GROUPCLUSTER on the TEXT statement. They should be removed, as they are not needed for what you're trying to accomplish. Second, add the STRIP option to strip off excess spaces.

View solution in original post

5 REPLIES 5
sbxkoenk
SAS Super FREQ

I have moved post to "Graphics Programming" board !

( Home > Programming > Graphics )

 

Koen

DanH_sas
SAS Super FREQ

Two things to try:

  1. Try using the SEGLABEL option on the VBARPARM instead using a TEXT plot. If that does not work,
  2. Add the STRIP option on the TEXT plot. The spaces at the end of the string might be causing alignment issues.

Hope this helps!

Dan

DanH_sas
SAS Super FREQ

Actually, #1 will not work for you, as you are displaying different statistics in the segments. Hopefully, the STRIP option will work for you.

DanH_sas
SAS Super FREQ

Sorry for the noise. I analyzed this further. The main issue causing your alignment issue is having the GROUP and GROUPCLUSTER on the TEXT statement. They should be removed, as they are not needed for what you're trying to accomplish. Second, add the STRIP option to strip off excess spaces.

Anita_n
Pyrite | Level 9

@DanH_sas @sbxkoenk  Thanks a lot, it worked 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 820 views
  • 3 likes
  • 3 in conversation