BookmarkSubscribeRSS Feed
Jeb1
Calcite | Level 5

Hello to the beautiful SAS community!

 

I am using datalabel option in my Proc sgplot vline which is grouped.

 

I would like to find a way to display the datalabel for only two variables group out of four. I can't find a solution either on the GRAPH side or on the ODS side.

 

Did I miss something?

 

Thanks a lot!

 

Kind regards,

Jeb

4 REPLIES 4
ballardw
Super User

Please show the code you are currently using and best would be to include some example data to graph to test the code with. The data should be in form of data step code pasted into a code box opened on the forum with the </> icon that appears above the main message windows.

The code box is important because the main message window will reformat text and often data step with data lines included will no longer run properly after the reformatting.

 

Data and code are needed because sometime what you want to do may require modifying the data set a bit such as adding variables for use and the code is so we have at least a vague idea what you attempted to create.

You should also provide a description that at least lets us know WHICH labels you want to appear.

Jeb1
Calcite | Level 5
/* Création de la sortie PDF */
ods PDF style = EGI file=X author = "X";
options nodate nonumber;
title "My Code";

PROC SGPLOT data = DCAT_RLS_TOTAL;
	title box=4 bcolor = CX00B050 &G1;
	VLINE periode / response = VAR4 group = annees_fin_ensemble markers markerattrs=(symbol=circlefilled size=8) datalabel;
	xaxis grid label = "Périodes";
	yaxis grid values = (85 to 100 by 5);
	refline X / axis = y lineattrs=(pattern=2 thickness=1px color=red) label = "Cible X%";
	keylegend / noborder title = ""; 
	format annees_fin_ensemble F_annees_fin_ensemble.;
run;

ODS PDF CLOSE;
PaigeMiller
Diamond | Level 26

@Jeb1 

Please don't ignore the request to provide sample data. Please don't ignore the request to provide sample data in a useable formatThe actual request from @ballardw said:

 

Please show the code you are currently using and best would be to include some example data to graph to test the code with. The data should be in form of data step code pasted into a code box opened on the forum with the </> icon that appears above the main message windows.

The code box is important because the main message window will reformat text and often data step with data lines included will no longer run properly after the reformatting.

--
Paige Miller
FreelanceReinh
Jade | Level 19

Hello @Jeb1 and welcome to the SAS Support Communities!

 

Maybe there's a more elegant way to achieve what you want, but one idea is to use two VLINE statements in the PROC SGPLOT step: one using the DATALABEL option and the other not using it.

 

Suppose that for annees_fin_ensemble in (2019, 2021) you want to display data labels, but not for the other years. Then you could create a dataset WANT like

data want;
set DCAT_RLS_TOTAL;
if annees_fin_ensemble in (2019, 2021) then do;
  _var4=var4;
  var4=.;
end;
run;

and use it in PROC SGPLOT:

proc sgplot data = want;
vline periode / response =  var4 group = annees_fin_ensemble markers markerattrs=(symbol=circlefilled size=8) name='part1';
vline periode / response = _var4 group = annees_fin_ensemble markers markerattrs=(symbol=circlefilled size=8) datalabel;
keylegend 'part1' / noborder title = ""; 
...
run;

So you overlay two VLINE plots with only slightly different options and restrict the KEYLEGEND to one of the plots to avoid duplication.

 

I suspect that the label specified in the REFLINE statement does not appear in the graph because you are using a variable (X) so that the label should also be supplied as a variable. (See the documentation of the LABEL option.)

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 4 replies
  • 1574 views
  • 0 likes
  • 4 in conversation