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

I have a data set with 3 variables as defined below - 

 

program 1         5         4        3         2

rank       1         2         3        4         5 

score    2.1     3.7       4.2     5.6      6.4

 

I have the output file from proc means as well with mean, std, min, max, etc.

I want to plot the score according to their ranks in a horizontal bar chart plot with the corresponding program names printed inside the bars. 

The graph should like something like the drawn plot in the pdf attached.

 

I have used [proc template] and [proc sgrender] to plot the graph (which I cannot upload because it's from a project I am consulting on and I apologize for that) but I cannot get to print the program names for each bar. 

Kindly help me. 

 

Thank You,

Neel.

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

I don't think you need to use PROC TEMPLATE for this. It is easy enough to create by using PROC SGPLOT. The key is to use the DATALABEL= option to specify the label (which you need to construct in a DATA step) and use the DATALABELFITPOLICY= option to put the label inside the bars:

data have;
input program score;
labl = cat("Program", put(program, 2.));
datalines;
1 2.1     
5 3.7
4 4.2
3 5.6
2 6.4
;

proc sort data=Have;
by descending Score;
run;

proc sgplot data=Have;
hbar program / response=score datalabel=labl datalabelfitpolicy=insidepreferred;
yaxis discreteorder=data display=(novalues noticks);
xaxis label="Score"; run;

If you do decide to use the GTL, the same options are supported by the BARCHARTPARM statement.

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

I don't think you need to use PROC TEMPLATE for this. It is easy enough to create by using PROC SGPLOT. The key is to use the DATALABEL= option to specify the label (which you need to construct in a DATA step) and use the DATALABELFITPOLICY= option to put the label inside the bars:

data have;
input program score;
labl = cat("Program", put(program, 2.));
datalines;
1 2.1     
5 3.7
4 4.2
3 5.6
2 6.4
;

proc sort data=Have;
by descending Score;
run;

proc sgplot data=Have;
hbar program / response=score datalabel=labl datalabelfitpolicy=insidepreferred;
yaxis discreteorder=data display=(novalues noticks);
xaxis label="Score"; run;

If you do decide to use the GTL, the same options are supported by the BARCHARTPARM statement.

arsinha
Fluorite | Level 6
This is amazing. Thank You so much sir. #respect

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 541 views
  • 2 likes
  • 2 in conversation