BookmarkSubscribeRSS Feed
EC27556
Quartz | Level 8

Hi, how can you add the number of observations used in an sgplot to a graph. I.e. for the below code, somewhere on the graph, or as a title if easier, I would like it to say "428 observations").

 

Ideally I'd like something that would change if I added a where statement to the data statement below. I.e. if I said (where=(enginesize>3)) then it would update the observation number in the graph produced to the actual number of relevant observations (obviously less than 428 in this case).

 

Thanks

 

proc sgplot data=sashelp.cars;
  histogram EngineSize / nbins=18;
  density EngineSize;
run;

 

3 REPLIES 3
ballardw
Super User

Where do you want it to appear?

Rick_SAS
SAS Super FREQ
data cars / view=cars;
set Sashelp.cars;
/* put WHERE clause here, if desired */
WHERE EngineSize > 3;
run;


proc sql noprint; 
select N(EngineSize) into :N trimmed 
from cars; 
quit;

%put &=N;

proc sgplot data=sashelp.cars;
  histogram EngineSize / nbins=18;
  density EngineSize;
  inset "N = &N" / border;
run;

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!

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