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

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

SASuserlot_0-1637111046218.png

 

1 ACCEPTED SOLUTION

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

View solution in original post

2 REPLIES 2
BrunoMueller
SAS Super FREQ

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

 

 

 

Ksharp
Super User
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;

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
  • 2 replies
  • 2050 views
  • 0 likes
  • 3 in conversation