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;
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;
Can you show us your data or part of it?
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/
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.
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;
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!
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.