BookmarkSubscribeRSS Feed
Quentin
Super User

I'm using PROC SGPLOT VLINE statement to make a series plot that plots the frequency of an event over time (by month).  Events are sparse, so some months have no events

 

Given data like below (two failures in January, one failure in February, three failures in March, one failure in June).

data have ;
input FailDate mmddyy10.;
cards ;
1/1/2018
1/2/2018
2/1/2018
3/1/2018
3/2/2018
3/3/2018
6/1/2018
;

 

 

I'm plotting like:

proc sgplot data=have;
  xaxis type=time interval=month ;
  vline FailDate / stat=freq markers;
  format FailDate yymon. ;
run ;

The resulting plot shows four points (Jan, Feb, Mar, Jun).  I would like it to show zeroes for April and May, because there were no events.

 

It feels like there should an easy way to do this?  SAS knows that it has a time axis, and it knows it's counting FailDate by month.  

 

If there isn't an easy way I know I can calculate the counts myself, and then force in rows with count=0 and then user a series plot to plot the line.  But I'd be happy if there were some option like how PROC TABULATE can use preloadfmt order=data missing=0 to force in zeroes for empty categories.

 

In reality I'll have a spaghetti plot, with one line for each group.

 

Thanks.

 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
1 REPLY 1
ballardw
Super User

Add some dates to the data for those months, summarize something to get counts and use a different statistic such as sum and/or the Freq= variablename

 

 

 

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
  • 1 reply
  • 606 views
  • 0 likes
  • 2 in conversation