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
Super User

Can you show us your data or part of it?

PeterClemmensen
Super User

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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 819 views
  • 0 likes
  • 3 in conversation