BookmarkSubscribeRSS Feed
CharlieHe
Fluorite | Level 6
Copied code from 9.2 document and tried to compile with error.
Code:
proc template;
define style Styles.MyDefault;
parent=Styles.Default;

style GraphData1 /
MarkerSymbol=DIAMOND;
style GraphData2 /
MarkerSymbol=CROSS;
style GraphData3 /
MarkerSymbol=CIRCLE;
end;

define statgraph testSymbols;
begingraph;
layout Overlay;
scatterPlot y=height x=weight / group=age
markerattrs=(symbol=MyDefault);
endlayout;
endgraph;
end;
run;


SAS LOG:

1 proc template;
2 define style Styles.MyDefault;
3 parent=Styles.Default;
4
5 style GraphData1 /
6 MarkerSymbol=DIAMOND;
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
7 style GraphData2 /
8 MarkerSymbol=CROSS;
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
9 style GraphData3 /
10 MarkerSymbol=CIRCLE;
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
11 end;
WARNING: Object will not be saved.
12
13 define statgraph testSymbols;
14 begingraph;
15 layout Overlay;
16 scatterPlot y=height x=weight / group=age
17 markerattrs=(symbol=MyDefault);
---------
772
ERROR 772-580: Syntax error: expecting a constant or a dynamic.
18 endlayout;
19 endgraph;
20 end;
WARNING: Object will not be saved.
21 run;
NOTE: PROCEDURE TEMPLATE used (Total process time):
real time 0.07 seconds
cpu time 0.06 seconds

WARNING: Errors were produced.
NOTE: The SAS System stopped processing this step because of errors.
22


23 proc template;
24 define style Styles.MyDefault;
25 parent=Styles.Default;
26
27 style GraphData1 /
28 LineStyle=6;
29 style GraphData2 /
30 LineStyle=4;
31 end;
NOTE: Overwriting existing template/link: Styles.MyDefault
NOTE: STYLE 'Styles.MyDefault' has been saved to: SASUSER.TEMPLAT
32
33 define statgraph testPattern;
34 begingraph;
35 layout overlay;
36 scatterplot y=height x=weight / group=gender;
37 lineparm yintercept=intercept slope=slope / group=gender
----------
22
76
ERROR 22-322: Syntax error, expecting one of the following: SLOPE, X, Y.
ERROR 76-322: Syntax error, statement will be ignored.
38 lineattrs=(pattern=MyDefault);
39 endlayout;
40 endgraph;
41 end;
WARNING: Object will not be saved.
42 run;
NOTE: PROCEDURE TEMPLATE used (Total process time):
real time 0.04 seconds
cpu time 0.04 seconds

WARNING: Errors were produced.
NOTE: The SAS System stopped processing this step because of errors.

Please tell me what is wrong. I have SAS 9.2 TS level 2M3.
6 REPLIES 6
DanH_sas
SAS Super FREQ
The symbol names need to be in quotes: markersymbol="diamond";
Where did you see this example?

Thanks,
Dan
Jay54
Meteorite | Level 14
Symbol values should be strings:

proc template;
define style Styles.MyDefault;
parent=Styles.Default;

style GraphData1 /
MarkerSymbol='DIAMOND';
style GraphData2 /
MarkerSymbol='CROSS';
style GraphData3 /
MarkerSymbol='CIRCLE';
end;
run;

Also, it is preferred to derive each style element from the parent, and change the attributes needed:
style GraphData3 from GraphData3 /


You need to remove the following option in the scatterplot statement:
Markerattrs=(symbol=MyDefault).

Lastly, to create the graph, you need:
proc sgrender data=foo template=testSymbols;
run;
Jay54
Meteorite | Level 14
To see your changes in a graph, use the following:

ods listing style=styles.mydefault;
proc sgrender data=sashelp.class template=testsymbols;
run;

The marker symbols you have defined will automatically be used for the first 3 values of the group variable. Since you have not derived your elements, they will only have markers, and not colors.

Use this code to see the legend with all values of age:

define statgraph testSymbols;
begingraph;
layout Overlay;
scatterPlot y=height x=weight / group=age name='s';
discretelegend 's';
endlayout;
endgraph;
CharlieHe
Fluorite | Level 6
Thanks Sanja. Now it works.
Just curious why the statement "Markerattrs=(symbol=MyDefault)" does not work.
I actually like the syntax since it will apply the style to the marker only.
With the statement "ods listing style=styles.mydefault;", it seems the style will apply globlally now.
Jay54
Meteorite | Level 14
Markerattrs=(symbol=circle) or markerattrs=(color=black) does work as expected. You just cannot assign a list of symbols or colors in this way.

ODS Graphics automatically applies the settings from the style to the group colors, symbols and line patterns. By doing this, all graphs in your report will have consistent attributes for the same group value. These colors, marker symbols etc have been carefully chosen by GUI experts to provide maximum clarity and discriminability between different groups when using the default styles.

Furthermore, there are many styles shipped by SAS for you to use. The whole idea is to create aesthetic and effective graphs out of the box without users having to spend time finding good combination of colors. Of course, if you need, you can design your own style too.

If you are not using a group variable, you can change the setting of the plot by using the markerattrs=(symbol=circle, color=black) or whatever you need. If you have a graph made up of multiple scatter or series plots, one per column, you can control the color and other attributes of each plot by using this feature.

In future release, there may be a way to set group colors, markers, etc in the syntax itself.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 2110 views
  • 0 likes
  • 3 in conversation