## sgplot vbar generating weekly/daily

Solved
Frequent Contributor
Posts: 77

# sgplot vbar generating weekly/daily

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;

``````

Accepted Solutions
Solution
‎10-10-2017 07:58 AM
Frequent Contributor
Posts: 77

## Re: sgplot vbar generating weekly/daily

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;``````

All Replies
PROC Star
Posts: 1,084

## Re: sgplot vbar generating weekly/daily

Can you show us your data or part of it?

PROC Star
Posts: 1,084

## Re: sgplot vbar generating weekly/daily

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/

Super User
Posts: 12,148

## Re: sgplot vbar generating weekly/daily

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.

Solution
‎10-10-2017 07:58 AM
Frequent Contributor
Posts: 77

## Re: sgplot vbar generating weekly/daily

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;``````
☑ This topic is solved.