Hi I am newly learning into Proc Template to create different graphs. I want to know how I can control the graph styles such as line colors, line pattern, symbols, fonts used in the graph. can you please guys suggest me what to do in the following code. I tried at SAS, but for me it looks too vast and some times going over my head 😪.
ODS LISTING CLOSE;
data cars;
set sashelp.cars;
engine=enginesize;
run;
PROC MEANS DATA= cars;
CLASS origin engine;
VAR horsepower;
OUTPUT OUT=summary (WHERE=(_type_ EQ 3)) N=n MEAN=mean STDDEV=stddev MIN=min
MAX=max;
RUN;
ODS LISTING;
DATA summary;
SET summary;
IF UPCASE(origin) EQ 'ASIA' THEN engine = engine-0.1;
IF UPCASE(origin) EQ 'USA' THEN engine = engine+0.1;
RUN;
PROC TEMPLATE;
DEFINE STATGRAPH errorbar;
BeginGraph;
EntryTitle "PhUSE 2010";
EntryTitle "Example Error Bar (Mean " {UNICODE '00B1'X}
" SD) Plot Using GTL";
Layout OVERLAY /
XAxisOpts=(LABEL="Engine Size")
YAxisOpts=(LABEL="Mean Horsepower");
ScatterPlot X=engine Y=mean /
GROUP=origin NAME="scatter"
YErrorLower=EVAL(mean-stddev);
/* YErrorUpper=EVAL(mean+stddev);*/
SeriesPlot X=engine Y=mean / GROUP=origin;
DiscreteLegend "scatter" / ACROSS=3 TITLE="Origin of Car";
EndLayout;
EndGraph;
END;
RUN;
options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nofmterr nobyline
noquotelenmax ;
ods escapechar = '^';
ods results on;
ods listing close;
ods rtf file = "\\xx\D\xx\Desktop\Graphs\sed-err-anno.rtf" style = table_rtf;* nogtitle nogfootnote;
PROC SGRENDER DATA=summary TEMPLATE=errorbar;
RUN;
ods rtf close;
ods listing close;
I am looking to change the color and pattern of the lines and symbols and the font in x axis y axis labels and legends in the following graph. I really appreciate your help and advise
data cars; set sashelp.cars; engine=enginesize; run; PROC MEANS DATA= cars; CLASS origin engine; VAR horsepower; OUTPUT OUT=summary (WHERE=(_type_ EQ 3)) N=n MEAN=mean STDDEV=stddev MIN=min MAX=max; RUN; DATA summary; SET summary; IF UPCASE(origin) EQ 'ASIA' THEN engine = engine-0.1; IF UPCASE(origin) EQ 'USA' THEN engine = engine+0.1; RUN; PROC TEMPLATE; DEFINE STATGRAPH errorbar; BeginGraph / BORDER=False datacontrastcolor=(gold navy green) datasymbol=(plus circle star); /*<------*/ EntryTitle "PhUSE 2010"; EntryTitle "Example Error Bar (Mean " {UNICODE '00B1'X} " SD) Plot Using GTL"; Layout OVERLAY / XAxisOpts=(LABEL="Engine Size") YAxisOpts=(LABEL="Mean Horsepower"); ScatterPlot X=engine Y=mean / GROUP=origin NAME="scatter" YErrorLower=EVAL(mean-stddev); /* YErrorUpper=EVAL(mean+stddev);*/ SeriesPlot X=engine Y=mean / GROUP=origin; DiscreteLegend "scatter" / ACROSS=3 TITLE="Origin of Car"; EndLayout; EndGraph; END; RUN; ods graphics /ATTRPRIORITY=none ; /*<------*/ options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nofmterr nobyline noquotelenmax ; ods escapechar = '^'; ods rtf file = "c:\temp\temp.rtf" style = rtf;* nogtitle nogfootnote; PROC SGRENDER DATA=summary TEMPLATE=errorbar; RUN; ods rtf close;
First of all, there is not need to use the Graph Template Language (GTL) to create this graph. Proc SGPLOT will do this with less code.
To control elements in your plots I recommend to have a look at these blogs:
https://blogs.sas.com/content/sgf/2017/09/15/proc-sgplot-theres-an-attrs-for-that/
and
https://blogs.sas.com/content/iml/2018/06/13/attrpriority-cycleattrs-styleattrs-ods-graphics.html
data cars; set sashelp.cars; engine=enginesize; run; PROC MEANS DATA= cars; CLASS origin engine; VAR horsepower; OUTPUT OUT=summary (WHERE=(_type_ EQ 3)) N=n MEAN=mean STDDEV=stddev MIN=min MAX=max; RUN; DATA summary; SET summary; IF UPCASE(origin) EQ 'ASIA' THEN engine = engine-0.1; IF UPCASE(origin) EQ 'USA' THEN engine = engine+0.1; RUN; PROC TEMPLATE; DEFINE STATGRAPH errorbar; BeginGraph / BORDER=False datacontrastcolor=(gold navy green) datasymbol=(plus circle star); /*<------*/ EntryTitle "PhUSE 2010"; EntryTitle "Example Error Bar (Mean " {UNICODE '00B1'X} " SD) Plot Using GTL"; Layout OVERLAY / XAxisOpts=(LABEL="Engine Size") YAxisOpts=(LABEL="Mean Horsepower"); ScatterPlot X=engine Y=mean / GROUP=origin NAME="scatter" YErrorLower=EVAL(mean-stddev); /* YErrorUpper=EVAL(mean+stddev);*/ SeriesPlot X=engine Y=mean / GROUP=origin; DiscreteLegend "scatter" / ACROSS=3 TITLE="Origin of Car"; EndLayout; EndGraph; END; RUN; ods graphics /ATTRPRIORITY=none ; /*<------*/ options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nofmterr nobyline noquotelenmax ; ods escapechar = '^'; ods rtf file = "c:\temp\temp.rtf" style = rtf;* nogtitle nogfootnote; PROC SGRENDER DATA=summary TEMPLATE=errorbar; RUN; ods rtf close;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.