SAS SGPLOT symbols and colors for markers

256 Views Asked by At

In the sgplot code below, the Asterisk symbol does not take the color defined by the code, displays lightgreen instead of blue.

ods graphics / attrpriority=none;
    proc sgplot data=unk;
    title 'Scatter Plot';
    styleattrs datacolors=(blue lightyellow lightsalmon) 
                    datasymbols=(Asterisk Circlefilled Diamondfilled);
           scatter x=S y=M / group=A
                    filledoutlinedmarkers
                    markeroutlineattrs=(color=black thickness=1);
    run;

Still the same error (attributes do not display the color defined in the code) with attribute map dataset, dataset and code below:

data mattrs;
        retain linecolor "black";
            infile datalines truncover;
            input ID Value markersymbol fillcolor;
                datalines;
                    U N circlefilled lightyellow
                    U R diamondfilled lightsalmon
                    U S asterisk blue
                    ;
    run;
    data unk;
        infile datalines truncover;
            input S $ Value $ M ID $;
                datalines;
                    ZB N 3 U
                    ZB R 5 U
                    ZB S 10 U
                    YQ N 11 U
                    YQ R 6 U
                    YQ S 7 U
                    XI N 1 U
                    XI R 5 U
                    XI S 2 U
                    TO N 9 U
                    TO R 3 U
                    TO S 10 U
                    ;
    run;    
    proc sgplot data=unk dattrmap=mattrs;
        scatter x=S y=M / group=Value attrid=U;
        yaxis min=0 max=100 type=log logstyle=logexpand logbase=10 grid;
    run;
    
1

There are 1 best solutions below

0
On BEST ANSWER
  1. The data is not being created properly based on the code provided. Ensure the sample data is generated correctly, specifically the mattrs data set.
  2. The symbol colour is not the same as the fill colour, use markercolor for the symbol colour. Personally, I prefer hex codes for numbers as it's easier to get exactly what you want. I changed the first colour to red as I couldn't see the light yellow on a screen.

This works for me.

data mattrs;
    retain linecolor "black";
    infile datalines truncover;
    input ID $  Value $ markersymbol : $20.  markercolor : $20.;
    datalines;
U N circlefilled red
U R diamondfilled lightsalmon
U S asterisk blue
                    ;
run;

data unk;
    infile datalines truncover;
    input S $ Value $ M ID $;
    datalines;
ZB N 3 U
ZB R 5 U
ZB S 10 U
YQ N 11 U
YQ R 6 U
YQ S 7 U
XI N 1 U
XI R 5 U
XI S 2 U
TO N 9 U
TO R 3 U
TO S 10 U
;
run;

proc sgplot data=unk dattrmap=mattrs;
    scatter x=S y=M / group=Value attrid=U;
    yaxis min=0 max=100 type=log logstyle=logexpand logbase=10 grid;
run;