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

Hi,

 

I need to add a percentage (i.e., the "%" character) to only one subgroup in a plot graph. I am using the following program:

data j1;
input
 Age $ var1 periovar1;
datalines;
 30-34 1 0.22
 30-34 2 0.01
 35-39 1 0.26
 35-39 2 0.03
 40-44 1 0.28
 40-44 2 0.03
 45-49 1 0.37
 45-49 2 0.05
 50-54 1 0.39
 50-54 2 0.06
 55-59 1 0.47
 55-59 2 0.08
 60-64 1 0.48
 60-64 2 0.08
 65-69 1 0.54
 65-69 2 0.08
 70-74 1 0.48
 70-74 2 0.09
 75-79 1 0.53
 75-79 2 0.11
 80-84 1 0.53
 80-84 2 0.11
 85-90 1 0.57
 85-90 2 0.11
;

proc format library=work;
  value
    var1_ 1= 'prevalence'
          2 = 'mean';
	run;

proc sgplot data=j1 noborder;
vbarparm category=age response=periovar1 / datalabel
 datalabelattrs=(family=arial size=11 weight=bold)
    fill group=var1 groupdisplay=cluster;
styleattrs datacolors=(green red);
yaxis grid label="" display=none 
   labelattrs=(family=arial size=18 weight=bold)
   valueattrs=(family=arial size=14 weight=bold);
xaxis label= 'age (years)'
   labelattrs=(family=arial size=18 weight=bold)
   valueattrs=(family=arial size=14 weight=bold)
 /*split age groups because of limited space*/ 
  fitpolicy=split splitchar="-"
  splitcharnodrop splitjustify=left;
keylegend /position=top title=""
  valueattrs=(family=arial size=14 weight=bold);
format var1 var1_. periovar1 percent.;
run;

The resulting graph is below. I want the "%" character to be associated only with the prevalence (the green plot) and not with the mean (the red plot). I appreciate any help in modifying the code to correct the plot.

Thanks.

 

plot.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I think the problem is that you have one variable PERIOVAR1 with two meanings. If these were two variables, you should be able to assign the data label to one variable with a % sign and the other variable would not have the % sign. (Actually, having one variable with two meanings is generally a bad idea no matter what you are doing, not just in the case of this plot)

 

You could then plot a line-bar chart where mean is the line and percent is the bar. 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n1mp0swy0atvzun1oeqlkrg8d89o.htm

 

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

I think the problem is that you have one variable PERIOVAR1 with two meanings. If these were two variables, you should be able to assign the data label to one variable with a % sign and the other variable would not have the % sign. (Actually, having one variable with two meanings is generally a bad idea no matter what you are doing, not just in the case of this plot)

 

You could then plot a line-bar chart where mean is the line and percent is the bar. 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n1mp0swy0atvzun1oeqlkrg8d89o.htm

 

 

--
Paige Miller
Jason2020
Obsidian | Level 7

Hi Paige,

I now have changed the response variable to 2 variables and used the information you provided, and it worked. Thank you very much for the quick reply. 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 2 replies
  • 554 views
  • 0 likes
  • 2 in conversation