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

I'm using the following code to begin. I'd like to divide the x variable OCCUR_DATE into monthly,/weekly/daily var charts for each vehicle. The macro will plot data counts for each individual vehicle.

 

%macro rept_plot_Cycle(num);
	title "&num Cycle plot";
	proc sgplot data=cycle_data;
		where VEHICLE_NO = "&num" 
		;
		yaxis label= "cycle count";
		vbar x=OCCUR_DATE y=count(fault_code);
	run;
%mend rept_plot_Cycle;

data _null_;
	array veh_no[39] _temporary_ (3725:3763)
;
	call execute('proc sql;');
	do i=1 to dim(veh_no) while (veh_no(i) ne .);
		call execute(cats('%nrstr(%rept_plot_Cycle)(',veh_no(i),')'));
	end;
	call execute('quit;');
run;

1 ACCEPTED SOLUTION

Accepted Solutions
capam
Pyrite | Level 9

I used the following code to solve most of the issue. It is a brute force approach but functional.

 

data have;
	set have;
	by vehicle_no;

	if first.VEHICLE_NO then
		cusum=0;
	cusum+1;
run;

proc sgplot data=have;
	where VEHICLE_NO = "&num"
	;
	yaxis label= "cumulative Incidents";
	scatter x=OCCUR_DATE y=cusum;
run;

data have;
	set have(drop=cusum);
run;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Can you show us your data or part of it?

PeterClemmensen
Tourmaline | Level 20

Also, the VBAR statement does not support the X= and Y= statements as the SERIES statement does. 

 

Check out this introduction to the VBAR statement in PROC SGPLOT here

 

https://blogs.sas.com/content/graphicallyspeaking/2016/11/27/getting-started-sgplot-part-2-vbar/

ballardw
Super User

Does your data currently have a date variable that contains a SAS date value?

If so then using a different format such as MONYY, WEEKU or DATE9. would provide different groups for the variable.

 

Did you get the desired output for a singe graph with the rept_plot_cycle macro? Your syntax for VBAR is incorrect.

I think you are intending

vbar occur_date / group=fault_code stat=freq;

 

I suspect that from what your are doing that By vehicle_no may be a better approach with #byval in the title.

 

capam
Pyrite | Level 9

I used the following code to solve most of the issue. It is a brute force approach but functional.

 

data have;
	set have;
	by vehicle_no;

	if first.VEHICLE_NO then
		cusum=0;
	cusum+1;
run;

proc sgplot data=have;
	where VEHICLE_NO = "&num"
	;
	yaxis label= "cumulative Incidents";
	scatter x=OCCUR_DATE y=cusum;
run;

data have;
	set have(drop=cusum);
run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 1333 views
  • 0 likes
  • 3 in conversation