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

Hi, 

 

I have result values as 424, 56, 33, 26, 20, 14, 13, 4, 2, 1, -7, -10, -13, -15, -20, -24, -35, -37, -38, -54, -69, -72, -84. I am plotting a bar chart using the following code. 

proc sgplot data=test;

vbar n/response=result datalabel;

xaxis label = 'N=xx' display=(novalues noticks);

yaxis label= 'Results' ;

run; 

Sairampulipati_0-1655839671382.png

After running the above code am getting result like this, but the I need to restrict y-axis values as -100 to 140 by 20 and 100&above to display within 140. For that I harcoded the value above 100 to  120 like (if result > 100 then result_ = 120; else result_ = result;) with that update I have run the same code changing ressponse = result_ (new variable created0 but the data label show the new hardcoded value as 120 for the observations above 100. But I wanted to show the actual result value 424 in the place of 120, is that possible. 

Sairampulipati_1-1655840172920.png

Thank you for your help in advance. 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Not commenting on whether this is a good idea or bad idea but it's possible. DATALABEL allows you specify a variable for the label so specify the original variable.

 

proc sgplot data=test1;
vbar n/response=result_ datalabel = result;
xaxis label='N=xx' display=(novalues noticks);
yaxis label='Results';
run;

@Sairampulipati wrote:

Thank you Miler, here is the code. 

data test;
input result 8.;
datalines;
424
56
33
26
20
14
13
4
2
1
-7
-10
-13
-15
-20
-24
-35
-37
-38
-54
-69
-72
-84
;
run;

data test;
set test;
n=_n_;
run;

proc sgplot data=test;
vbar n/response=result datalabel;
xaxis label='N=xx' display=(novalues noticks);
yaxis label='Results';
run;

data test1;
set test;
if result > 100 then result_=120;
else result_=result;
run;

proc sgplot data=test1;
vbar n/response=result_ datalabel;
xaxis label='N=xx' display=(novalues noticks);
yaxis label='Results';
run;

I am new to plots so I am not sure how to apply formats to data to show 120 as 424 in plot. 

 


 

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Its really hard to know what you did when you show us small parts of your program, and write words to describe the rest of the program. Show us the relevant parts of your program, PROCs and DATA steps need to be complete. Do not show us partial PROCs or partial DATA steps.

 

Also, have you tried formatting the data so 120 is shown as 424?

--
Paige Miller
Sairampulipati
Fluorite | Level 6

Thank you Miler, here is the code. 

data test;
input result 8.;
datalines;
424
56
33
26
20
14
13
4
2
1
-7
-10
-13
-15
-20
-24
-35
-37
-38
-54
-69
-72
-84
;
run;

data test;
set test;
n=_n_;
run;

proc sgplot data=test;
vbar n/response=result datalabel;
xaxis label='N=xx' display=(novalues noticks);
yaxis label='Results';
run;

data test1;
set test;
if result > 100 then result_=120;
else result_=result;
run;

proc sgplot data=test1;
vbar n/response=result_ datalabel;
xaxis label='N=xx' display=(novalues noticks);
yaxis label='Results';
run;

I am new to plots so I am not sure how to apply formats to data to show 120 as 424 in plot. 

 

Reeza
Super User

Not commenting on whether this is a good idea or bad idea but it's possible. DATALABEL allows you specify a variable for the label so specify the original variable.

 

proc sgplot data=test1;
vbar n/response=result_ datalabel = result;
xaxis label='N=xx' display=(novalues noticks);
yaxis label='Results';
run;

@Sairampulipati wrote:

Thank you Miler, here is the code. 

data test;
input result 8.;
datalines;
424
56
33
26
20
14
13
4
2
1
-7
-10
-13
-15
-20
-24
-35
-37
-38
-54
-69
-72
-84
;
run;

data test;
set test;
n=_n_;
run;

proc sgplot data=test;
vbar n/response=result datalabel;
xaxis label='N=xx' display=(novalues noticks);
yaxis label='Results';
run;

data test1;
set test;
if result > 100 then result_=120;
else result_=result;
run;

proc sgplot data=test1;
vbar n/response=result_ datalabel;
xaxis label='N=xx' display=(novalues noticks);
yaxis label='Results';
run;

I am new to plots so I am not sure how to apply formats to data to show 120 as 424 in plot. 

 


 

Sairampulipati
Fluorite | Level 6

Thank you very much Reeza for the help, certainly it worked well. The read wants in such a way that above hundred should be like 100+ in the y-axis and actual result values in the data label. I have changed the code to  

proc sgplot data=test1;

vbar n/response=result_ datalabel=result;

xaxis label='N=xx' display=(novalues noticks);

yaxis label='Results' values=(-100 -80 -60 -40 -20 0 20 40 60 80 100 120) valuesdisplay=('-100' '-80' '-60' '-40' '-20' '0' '20' '40' '60' '80' '100' '100+');

run;

And now the output looks as per the reader requirement 

Sairampulipati_0-1655891235060.png

 

ballardw
Super User

Are you actually intending to mislead the reader of your graph and imply that the value is actually 120 when in reality it was 424? Or do you want something so that the height of the bar is not drastically longer than others?

 

Consider (note, I am nice enough to provide a data set to actually graph):

data example;
   do y=424, 56, 33, 26, 20, 14, 13, 4, 2, 1, -7, -10, -13, -15, -20, -24, -35, -37, -38, -54, -69, -72, -84;
      x +1;
      output;
   end;
run; 

/* as is*/
proc sgplot data=example;
   vbar x/response=y datalabel;
   xaxis label = 'N=xx' display=(novalues noticks);
   yaxis label= 'Results' ;
run;

/* break in yaxis*/
proc sgplot data=example;
   vbar x/response=y datalabel;
   xaxis label = 'N=xx' display=(novalues noticks);
   yaxis label= 'Results' ranges=(-100-100 400-450) ;
run;

The second graph makes much more sense than trying to corrupt an actual value.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 343 views
  • 1 like
  • 4 in conversation