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;
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,
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:
Bart
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.