Data visualization with SAS programming

Style template compile error

Reply
Occasional Contributor
Posts: 13

Style template compile error

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.
SAS Super FREQ
Posts: 889

Re: Style template compile error

The symbol names need to be in quotes: markersymbol="diamond";
Where did you see this example?

Thanks,
Dan
SAS Super FREQ
Posts: 1,080

Re: Style template compile error

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;
Occasional Contributor
Posts: 13

Re: Style template compile error

SAS Super FREQ
Posts: 1,080

Re: Style template compile error

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;
Occasional Contributor
Posts: 13

Re: Style template compile error

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.
SAS Super FREQ
Posts: 1,080

Re: Style template compile error

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.
Ask a Question
Discussion stats
  • 6 replies
  • 665 views
  • 0 likes
  • 3 in conversation