问题
What I'm trying to do:
I'm creating plots using the code below. PERIOD has 3 different values, so the plot and plot2 statements each create 3 series on the plot via an x*y=z type of plot request. I want the 3 series from the plot statement to have symbols that are joined up, and I want the 3 series from the plot2 statement to have symbols that are not joined up. Whatever solution I come up with needs to work inside a macro.
The problem
No matter what I try, all 6 series on each chart end up using the same symbols. All the other plot options I'm defining outside the proc gplot calls are being picked up correctly, so what am I doing wrong with the symbol definitions? I would be grateful if someone could post an example of the correct syntax.
References
I found this link, which produces a very similar sort of plot with different symbols for the plot and plot2 series, but it doesn't use an x*y=z plot request:
http://support.sas.com/techsup/technote/ts422.html
I also found this link, which contains some code that uses an x*y = z request but without a plot2 statement:
http://www.sfu.ca/sasdoc/sashtml/ets/chap2/sect27.htm
This page claims it's possible to do both at the same time and get different symbols for each series using symbols statments, but doesn't actually provide the necessary code to do it:
http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/gplot-plot2.htm#gplot-fig5
Code examples
If I run this code, all 6 series are plotted with interpol = none:
%macro sr_elas_plots(VAR);
goptions reset = all;
axis1 label=(angle = 90);
legend1 label=('Obs. elasticity');
legend2 label=('Quote volume');
proc gplot data = _p_&VAR;
symbol1 interpol=join value=dot height=3;
symbol2 interpol=join value=dot height=3;
symbol3 interpol=join value=dot height=3;
plot Elasticity*&VAR = PERIOD / legend = legend1 vaxis=axis1;
symbol1 interpol=none value = dot height=3;
symbol2 interpol=none value = dot height=3;
symbol3 interpol=none value = dot height=3;
plot2 QUOTES*&VAR = PERIOD / legend = legend2;
by NBIND CHANNEL;
run;
quit;
%mend sr_elas_plots;
If I run this code, however, all 6 are plotted with interpol = join:
%macro sr_elas_plots(VAR);
goptions reset = all;
axis1 label=(angle = 90);
legend1 label=('Obs. elasticity');
legend2 label=('Quote volume');
proc gplot data = _p_&VAR;
symbol1 interpol=join value=dot height=3;
symbol2 interpol=join value=dot height=3;
symbol3 interpol=join value=dot height=3;
plot Elasticity*&VAR = PERIOD / legend = legend1 vaxis=axis1;
symbol4 interpol=none value = dot height=3;
symbol5 interpol=none value = dot height=3;
symbol6 interpol=none value = dot height=3;
plot2 QUOTES*&VAR = PERIOD / legend = legend2;
by NBIND CHANNEL;
run;
quit;
%mend sr_elas_plots;
Other things I've tried
- If I move the 6 different symbol statements so they're all before the first plot statement, all 6 series are plotted with interpol = join.
- If I move the 6 different symbol statements outside the proc gplot but still inside the macro, all 6 series are plotted with interpol = join.
- If I move the 6 different symbol statements outside the macro, and remove the goptions reset=all from the macro, all 6 series are plotted with interpol = join.
- If I assign 6 different value= options in the 6 different symbol statements (to try to force them to plot different symbols), the value from symbol4 is used for all 6 series.
- If I use 2 variables with 6 different values for z in my 2 x*y = z requests, the same thing still happens.
How can I get 3 series of each type when I have an x*y=z plot request in both the plot and plot2 statements?
回答1:
Fixed! From deep within the documentation for the symbol statement:
Controlling Consecutive SYMBOL Statements
If you specify consecutively numbered SYMBOL statements and you want SAS/GRAPH to use each definition only once, use color specifications to ensure each SYMBOL statement generates only one symbol definition.
All I had to do was add a color= option to each of the 6 symbol statements, and then each one was used exactly once in the order I expected. This is certainly one of the less intuitive aspects of SAS that I've come across, to put it mildly.
来源:https://stackoverflow.com/questions/9521169/how-can-i-use-different-symbols-for-groups-of-xy-z-plots-in-proc-gplot