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