Hello everyone, I am trying to get a graph in a pdf in SAS from a table with 3 columns, the first ("fecha") has the type date: 10MAR22, 09MAR22, etc. the second column ("Rango_horas") has two values, "OFF-WORK" and "WORK", so each date value will be duplicated, 10MAR22 will have "OFF-WORK" and "WORK", and the last column (" AVG") has the average % of cpu used, i.e. a number.
I would like to make a bar graph showing the different dates and the value that AVG has for OFF-WORK and WORK for each of the dates.
I have this code:
ODS pdf file = '/xx/xx/xx/Namepdf.pdf';
Axis1
STYLE=1
WIDTH=1
MINOR=NONE
LABEL=( "%CPU")
ORDER=(0 TO 100 BY 10)
;
Axis2
STYLE=1
WIDTH=1
LABEL=( "Fecha")
VALUE=NONE
;
TITLE;
TITLE1 "TEST";
FOOTNOTE;
PROC GCHART DATA=WORK.QUERY_FOR_TEST1
;
VBAR
fecha
/
CLIPREF
SPACE=15
FRAME TYPE=SUM
COUTLINE=BLACK
RAXIS=AXIS1
MAXIS=AXIS2
LREF=4
CREF=LTGRAY
AUTOREF
;
/* -------------------------------------------------------------------
End of task code
------------------------------------------------------------------- */
RUN; QUIT;
TITLE; FOOTNOTE;
When I run this it adds the avg values of offwork and work, it does not distinguish the "Rango_horas" column and it creates a column for each date, I would like to see 2 columns for each date value. Would this be possible?
Thank you very much in advance
proc sgplot dta=have;
vbar date / response=avg group=rango_horas groupdisplay=cluster;
run;
Highly recommend SGPLOT instead of GCHART/GPLOT.
I think you're looking for the clustered bar chart (first image)
https://robslink.com/SAS/ods2/aaaindex.htm
@Abelp9 wrote:
Hello everyone, I am trying to get a graph in a pdf in SAS from a table with 3 columns, the first ("fecha") has the type date: 10MAR22, 09MAR22, etc. the second column ("Rango_horas") has two values, "OFF-WORK" and "WORK", so each date value will be duplicated, 10MAR22 will have "OFF-WORK" and "WORK", and the last column (" AVG") has the average % of cpu used, i.e. a number.
I would like to make a bar graph showing the different dates and the value that AVG has for OFF-WORK and WORK for each of the dates.
I have this code:
ODS pdf file = '/xx/xx/xx/Namepdf.pdf'; Axis1 STYLE=1 WIDTH=1 MINOR=NONE LABEL=( "%CPU") ORDER=(0 TO 100 BY 10) ; Axis2 STYLE=1 WIDTH=1 LABEL=( "Fecha") VALUE=NONE ; TITLE; TITLE1 "TEST"; FOOTNOTE; PROC GCHART DATA=WORK.QUERY_FOR_TEST1 ; VBAR fecha / CLIPREF SPACE=15 FRAME TYPE=SUM COUTLINE=BLACK RAXIS=AXIS1 MAXIS=AXIS2 LREF=4 CREF=LTGRAY AUTOREF ; /* ------------------------------------------------------------------- End of task code ------------------------------------------------------------------- */ RUN; QUIT; TITLE; FOOTNOTE;
When I run this it adds the avg values of offwork and work, it does not distinguish the "Rango_horas" column and it creates a column for each date, I would like to see 2 columns for each date value. Would this be possible?
Thank you very much in advance
proc sgplot dta=have;
vbar date / response=avg group=rango_horas groupdisplay=cluster;
run;
Highly recommend SGPLOT instead of GCHART/GPLOT.
I think you're looking for the clustered bar chart (first image)
https://robslink.com/SAS/ods2/aaaindex.htm
@Abelp9 wrote:
Hello everyone, I am trying to get a graph in a pdf in SAS from a table with 3 columns, the first ("fecha") has the type date: 10MAR22, 09MAR22, etc. the second column ("Rango_horas") has two values, "OFF-WORK" and "WORK", so each date value will be duplicated, 10MAR22 will have "OFF-WORK" and "WORK", and the last column (" AVG") has the average % of cpu used, i.e. a number.
I would like to make a bar graph showing the different dates and the value that AVG has for OFF-WORK and WORK for each of the dates.
I have this code:
ODS pdf file = '/xx/xx/xx/Namepdf.pdf'; Axis1 STYLE=1 WIDTH=1 MINOR=NONE LABEL=( "%CPU") ORDER=(0 TO 100 BY 10) ; Axis2 STYLE=1 WIDTH=1 LABEL=( "Fecha") VALUE=NONE ; TITLE; TITLE1 "TEST"; FOOTNOTE; PROC GCHART DATA=WORK.QUERY_FOR_TEST1 ; VBAR fecha / CLIPREF SPACE=15 FRAME TYPE=SUM COUTLINE=BLACK RAXIS=AXIS1 MAXIS=AXIS2 LREF=4 CREF=LTGRAY AUTOREF ; /* ------------------------------------------------------------------- End of task code ------------------------------------------------------------------- */ RUN; QUIT; TITLE; FOOTNOTE;
When I run this it adds the avg values of offwork and work, it does not distinguish the "Rango_horas" column and it creates a column for each date, I would like to see 2 columns for each date value. Would this be possible?
Thank you very much in advance
Strongly agree with @Reeza that moving to SGPLOT is the way to go.
Gchart would require a Group=variablename and likely a GAXIS statement for "groups" to display. And possibly a Subgroup=variable
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.