BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Abelp9
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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


 

View solution in original post

2 REPLIES 2
Reeza
Super User
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


 

ballardw
Super User

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 2 replies
  • 699 views
  • 4 likes
  • 3 in conversation