BookmarkSubscribeRSS Feed
NguyenThanhTra
Calcite | Level 5

Hi all,

 

I'm trying to plot vbar with group option. The current results are as follows:

 

PROC SQL NOPRINT;
	CREATE TABLE TEMP00 AS 
		SELECT MAKE, ORIGIN, COUNT(*) AS NUM, MEAN(INVOICE) AS  INVOICE, MEAN(MPG_CITY) AS MPG_CITY
			FROM SASHELP.CARS
				GROUP BY MAKE, ORIGIN
					HAVING (CALCULATED NUM)>10
						ORDER BY ORIGIN, (CALCULATED INVOICE);
QUIT;

PROC SGPLOT DATA=TEMP00;
	VBAR MAKE/ RESPONSE=INVOICE GROUP=ORIGIN NOOUTLINE  MISSING ;
	VLINE MAKE/ RESPONSE=MPG_CITY GROUP=ORIGIN  Y2AXIS LINEATTRS=(COLOR=CX9CBA5F PATTERN=SOLID THICKNESS=2PX)  
		MARKERATTRS=(SYMBOL=CIRCLEFILLED COLOR=CX9CBA5F) MARKERS MISSING;
	TITLE "Summary data by Make";
	Y2AXIS LABEL="Mean MPG City";
	YAXIS LABEL="Mean Invoice";
	XAXIS LABEL="Make" DISCRETEORDER=DATA;
	LABEL INVOICE="Mean Invoice" MPG_CITY="Mean MPG City";
RUN;

Sgplot.png

The graph divides groups by color. What I want is a graph that divides the groups by distance. Please tell me how to do it.

Sincerely thank you,

1 REPLY 1
yabwon
Amethyst | Level 16

if you don't mind disgusting [😅] solution try this:

PROC SQL NOPRINT;
	CREATE TABLE TEMP00 AS 
		SELECT MAKE, ORIGIN, COUNT(*) AS NUM, MEAN(INVOICE) AS  INVOICE, MEAN(MPG_CITY) AS MPG_CITY
			FROM SASHELP.CARS
				GROUP BY MAKE, ORIGIN
					HAVING (CALCULATED NUM)>10
						ORDER BY ORIGIN, (CALCULATED INVOICE);
QUIT;

data TEMP01;
  set TEMP00 end=eof;
  by ORIGIN notsorted;
  output;
  if last.ORIGIN and not EOF;
    INVOICE = .;
    MPG_CITY = .;
    i + 1;
    MAKE = repeat(" ", i) !! "12"x;
    output;
run;

PROC SGPLOT DATA=TEMP01;
	VBAR MAKE/ RESPONSE=INVOICE GROUP=ORIGIN NOOUTLINE  MISSING /*!*/ NOZEROBARS /*!*/  ;
	VLINE MAKE/ RESPONSE=MPG_CITY GROUP=ORIGIN  Y2AXIS LINEATTRS=(COLOR=CX9CBA5F PATTERN=SOLID THICKNESS=2PX)  
		MARKERATTRS=(SYMBOL=CIRCLEFILLED COLOR=CX9CBA5F) MARKERS MISSING;
	TITLE "Summary data by Make";
	Y2AXIS LABEL="Mean MPG City";
	YAXIS LABEL="Mean Invoice";
	XAXIS LABEL="Make" DISCRETEORDER=DATA;
	LABEL INVOICE="Mean Invoice" MPG_CITY="Mean MPG City";
RUN;

result:

yabwon_0-1680258394501.png

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 762 views
  • 0 likes
  • 2 in conversation