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

Dear all,

Does anyone know how to specify the value for ticks on axis as percentage (e.g. '8%') instead of number (e.g. '8') for a scatter plot ?

I used 'Proc sgplot' to create a scatter plot for proportion of diabetes in male and female. The Y axis is proportion and I want to display percentage here. Thanks a lot!

 

 

Best,

 

Feng Liang

1 ACCEPTED SOLUTION

Accepted Solutions
6 REPLIES 6
Jagadishkatam
Amethyst | Level 16
Could you please send the proc sgplot code you are using. Before that you might try using the proc format as below


proc format;
value pct
low - 1='1%'
2-<3='2%'
3-<4='4%';
run;

you can extend the format. then you need to apply this format in the sgplot procedure for the y axis variable.
Thanks,
Jag
Lao_feng
Obsidian | Level 7

Dear ,

The following are my codes:

 

 

Lao_feng
Obsidian | Level 7

Sorry, the codes were not posted properly. I post them again.

 

data pdi;
INPUT Gender $ Proportion;  
cards;
Male    10.6  
Female  28.0

;
RUN;


PROC SGPLOT DATA=pdi;
SCATTER Y=Proportion X=gender/ datalabel=proportion ;
YAXIS VALUES=(0 TO 40 BY 10) LABEL="Proportion " LABELATTRS=(size=13 );
XAXIS LABEL="Proportion of diabetes by gender"  ;
RUN;QUIT;

 

Thanks!

Feng Liang

Jagadishkatam
Amethyst | Level 16

In that case you coudl try something as below

 

data pdi;
INPUT Gender $ Proportion;  
cards;
Male    10.6  
Female  28.0
;
RUN;

proc format;
value pct
10.6='10.6%'
28.0='28.0%'
;

use this format on the variable in proc sgplot
Thanks,
Jag
JeffMeyers
Barite | Level 11

Hello,

   I would just divide your proportions by 100 and add the percent12.1 format to it.  I had to adjust the y axis values (didn't change your label yet) afterwards.  Here's what I got with your code:

 

 data pdi;
input gender $ proportion;
cards;
Male 10.6
Female 28.0
;
run;
data pdi2;
set pdi;
proportion=proportion/100;
run;

ods graphics /reset;

proc sgplot data=pdi2;
scatter y=proportion x=gender / datalabel=proportion;
yaxis values=(0 to 0.4 by 0.1) Label='Proportion' labelattrs=(size=13);
xaxis label='Proportion of diabetes by gender';
format proportion percent12.1;
run;

 

SGPlot.png

Lao_feng
Obsidian | Level 7

Dear JeffMeyers,

Thank you very much !

 

Regards,

Feng Liang

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
  • 6 replies
  • 9250 views
  • 1 like
  • 3 in conversation