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

Hi, fellow SAS users-

 

First-time poster, here, so please give tips/observations on how to improve posts. 

 

I'm trying to create a dot plot in which the dots have data labels to two decimal places and the x-axis value labels follow a format that I've predefined.  I can't seem to get both at the same time, however. 

 

I have some lines of code that assign the following labels to the values 0-3 of the variable "assess": 

 

PROC FORMAT;
	value assess 0 = "Strongly Disagree" 1 = "Disagree" 2 = "Agree" 3 = "Strongly Agree";
RUN;

Later in the code, I create a data set with the variable "assess", limiting it to two decimals. 

DATA coal_long2;
	MERGE coal_long formerge;
	BY Coalition;
	format assess d4.2;
RUN;	

When I create the dot plot using this code: 

 

/*Dot Chart*/
/*Figure 1:  Mean Self-Assessment by Coalition*/
ods listing style=listing;
ods listing gpath="H:\Coalitions\";
ods graphics on / imagename="figure1a";
ods graphics / width=8in height=7in;
PROC SGPLOT data=coal_long2;
	format Coalition Coalition. assess assess.;
	dot Coalition / response=assess stat=mean datalabel limitstat=clm; 
	title "Figure 1. Mean Self-Assessment (By Coalition)";
RUN;
ods graphics off;

I get this chart, with value labels on the x-axis, but data labels to many decimal points: 

 figure1a21.png

 

 

On the other hand, when I remove the argument that applies the value labels ("assess assess."), with this code: 

/*Dot Chart*/
/*Figure 1:  Mean Self-Assessment by Coalition*/
ods listing style=listing;
ods listing gpath="H:\Coalitions\";
ods graphics on / imagename="figure1a";
ods graphics / width=8in height=7in;
PROC SGPLOT data=coal_long2;
	format Coalition Coalition.;
	dot Coalition / response=assess stat=mean datalabel limitstat=clm; 
	title "Figure 1. Mean Self-Assessment (By Coalition)";
RUN;
ods graphics off;

 

I get data labels to two decimals, but no value labels. 

 figure1a23.png

 

 

I'm clearly not understanding SAS's formatting procedures; there's something I'm missing "upstream," but I can't figure out what it is.  Could someone throw me a bone, here? 

 

Thanks,

David

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You can assign a different variable as the datalabel, so use two variables here, that are essentially identical.

 

Format the one for the datalabel using 8.2 and then format the one with the format required for the axis.

 

DATA coal_long2;
	MERGE coal_long formerge;
	BY Coalition;

dl = assess;

format assess assess.;
format dl F8.2;

RUN;	


/*Dot Chart*/
/*Figure 1:  Mean Self-Assessment by Coalition*/
ods listing style=listing;
ods listing gpath="H:\Coalitions\";
ods graphics on / imagename="figure1a";
ods graphics / width=8in height=7in;
PROC SGPLOT data=coal_long2;
	format Coalition Coalition. assess assess.;
	dot Coalition / response=assess stat=mean datalabel=dl limitstat=clm; 
	title "Figure 1. Mean Self-Assessment (By Coalition)";
RUN;
ods graphics off;

 


@dbcrow wrote:

Hi, fellow SAS users-

 

First-time poster, here, so please give tips/observations on how to improve posts. 

 

I'm trying to create a dot plot in which the dots have data labels to two decimal places and the x-axis value labels follow a format that I've predefined.  I can't seem to get both at the same time, however. 

 

I have some lines of code that assign the following labels to the values 0-3 of the variable "assess": 

 

PROC FORMAT;
	value assess 0 = "Strongly Disagree" 1 = "Disagree" 2 = "Agree" 3 = "Strongly Agree";
RUN;

Later in the code, I create a data set with the variable "assess", limiting it to two decimals. 

DATA coal_long2;
	MERGE coal_long formerge;
	BY Coalition;
	format assess d4.2;
RUN;	

When I create the dot plot using this code: 

 

/*Dot Chart*/
/*Figure 1:  Mean Self-Assessment by Coalition*/
ods listing style=listing;
ods listing gpath="H:\Coalitions\";
ods graphics on / imagename="figure1a";
ods graphics / width=8in height=7in;
PROC SGPLOT data=coal_long2;
	format Coalition Coalition. assess assess.;
	dot Coalition / response=assess stat=mean datalabel limitstat=clm; 
	title "Figure 1. Mean Self-Assessment (By Coalition)";
RUN;
ods graphics off;

I get this chart, with value labels on the x-axis, but data labels to many decimal points: 

 figure1a21.png

 

 

On the other hand, when I remove the argument that applies the value labels ("assess assess."), with this code: 

/*Dot Chart*/
/*Figure 1:  Mean Self-Assessment by Coalition*/
ods listing style=listing;
ods listing gpath="H:\Coalitions\";
ods graphics on / imagename="figure1a";
ods graphics / width=8in height=7in;
PROC SGPLOT data=coal_long2;
	format Coalition Coalition.;
	dot Coalition / response=assess stat=mean datalabel limitstat=clm; 
	title "Figure 1. Mean Self-Assessment (By Coalition)";
RUN;
ods graphics off;

 

I get data labels to two decimals, but no value labels. 

 figure1a23.png

 

 

I'm clearly not understanding SAS's formatting procedures; there's something I'm missing "upstream," but I can't figure out what it is.  Could someone throw me a bone, here? 

 

Thanks,

David


 

View solution in original post

2 REPLIES 2
Reeza
Super User

You can assign a different variable as the datalabel, so use two variables here, that are essentially identical.

 

Format the one for the datalabel using 8.2 and then format the one with the format required for the axis.

 

DATA coal_long2;
	MERGE coal_long formerge;
	BY Coalition;

dl = assess;

format assess assess.;
format dl F8.2;

RUN;	


/*Dot Chart*/
/*Figure 1:  Mean Self-Assessment by Coalition*/
ods listing style=listing;
ods listing gpath="H:\Coalitions\";
ods graphics on / imagename="figure1a";
ods graphics / width=8in height=7in;
PROC SGPLOT data=coal_long2;
	format Coalition Coalition. assess assess.;
	dot Coalition / response=assess stat=mean datalabel=dl limitstat=clm; 
	title "Figure 1. Mean Self-Assessment (By Coalition)";
RUN;
ods graphics off;

 


@dbcrow wrote:

Hi, fellow SAS users-

 

First-time poster, here, so please give tips/observations on how to improve posts. 

 

I'm trying to create a dot plot in which the dots have data labels to two decimal places and the x-axis value labels follow a format that I've predefined.  I can't seem to get both at the same time, however. 

 

I have some lines of code that assign the following labels to the values 0-3 of the variable "assess": 

 

PROC FORMAT;
	value assess 0 = "Strongly Disagree" 1 = "Disagree" 2 = "Agree" 3 = "Strongly Agree";
RUN;

Later in the code, I create a data set with the variable "assess", limiting it to two decimals. 

DATA coal_long2;
	MERGE coal_long formerge;
	BY Coalition;
	format assess d4.2;
RUN;	

When I create the dot plot using this code: 

 

/*Dot Chart*/
/*Figure 1:  Mean Self-Assessment by Coalition*/
ods listing style=listing;
ods listing gpath="H:\Coalitions\";
ods graphics on / imagename="figure1a";
ods graphics / width=8in height=7in;
PROC SGPLOT data=coal_long2;
	format Coalition Coalition. assess assess.;
	dot Coalition / response=assess stat=mean datalabel limitstat=clm; 
	title "Figure 1. Mean Self-Assessment (By Coalition)";
RUN;
ods graphics off;

I get this chart, with value labels on the x-axis, but data labels to many decimal points: 

 figure1a21.png

 

 

On the other hand, when I remove the argument that applies the value labels ("assess assess."), with this code: 

/*Dot Chart*/
/*Figure 1:  Mean Self-Assessment by Coalition*/
ods listing style=listing;
ods listing gpath="H:\Coalitions\";
ods graphics on / imagename="figure1a";
ods graphics / width=8in height=7in;
PROC SGPLOT data=coal_long2;
	format Coalition Coalition.;
	dot Coalition / response=assess stat=mean datalabel limitstat=clm; 
	title "Figure 1. Mean Self-Assessment (By Coalition)";
RUN;
ods graphics off;

 

I get data labels to two decimals, but no value labels. 

 figure1a23.png

 

 

I'm clearly not understanding SAS's formatting procedures; there's something I'm missing "upstream," but I can't figure out what it is.  Could someone throw me a bone, here? 

 

Thanks,

David


 

dbcrow
Obsidian | Level 7

Many thanks, Reeza.  It took a little bit of doing, but I got some code that worked! 

 

Best,

David

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 5203 views
  • 2 likes
  • 2 in conversation