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

Hello SasCommunity, I need your help.

 

I have 3 columns Coco1, Coco2 and alert. alert is just composed by 0 or 1. I managed to plot Coco1 vs Coco2 by grouping them regarding if alert = 0 or 1 but when I tried to assign the black color for the ones with alert = 0 and the red color for the ones with alert = 1, it doesn't work anymore (all circles are in black).

 

Zoom.png


I tried "styleattrs" or "datacolors = (red black)" next to "data=affichage" but nothing worked.

 

Here's my code :

 

proc sgplot data=Affichage;
/*  styleattrs datacolors=(black red) datasymbols=(circlefilled);*/

 scatter x=EC_rate y=NI_rate/ group=alert markerattrs=(color=black symbol=circlefilled); ;

 lineparm x=0 y=0 slope=1/ lineattrs=(color=green) curvelabel="100%";
 lineparm x=0 y=0 slope=.5/ lineattrs=(color=red) curvelabel="50%";
 lineparm x=0 y=0 slope=.25/ lineattrs=(color=blue) curvelabel="25%";
 title "Zoom coco";
 xaxis grid min=0;
 yaxis grid;
run;

  

Can someone help me please? Thanks in advance

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Use an attributes map:

 

data attrmap;
retain id "myid";
length markercolor $ 5;
input value $ markercolor $;
cards;
0 red
1 black
;
run;

proc sgplot data=Affichage dattrmap=attrmap;
/*  styleattrs datacolors=(black red) datasymbols=(circlefilled);*/

 scatter x=EC_rate y=NI_rate/ group=alert markerattrs=(color=black symbol=circlefilled) attrid=myid;

 lineparm x=0 y=0 slope=1/ lineattrs=(color=green) curvelabel="100%";
 lineparm x=0 y=0 slope=.5/ lineattrs=(color=red) curvelabel="50%";
 lineparm x=0 y=0 slope=.25/ lineattrs=(color=blue) curvelabel="25%";
 title "Zoom coco";
 xaxis grid min=0;
 yaxis grid;
run;

Take a look at this post for more details.

 

Hope this helps!

Dan

View solution in original post

4 REPLIES 4
DanH_sas
SAS Super FREQ

Use an attributes map:

 

data attrmap;
retain id "myid";
length markercolor $ 5;
input value $ markercolor $;
cards;
0 red
1 black
;
run;

proc sgplot data=Affichage dattrmap=attrmap;
/*  styleattrs datacolors=(black red) datasymbols=(circlefilled);*/

 scatter x=EC_rate y=NI_rate/ group=alert markerattrs=(color=black symbol=circlefilled) attrid=myid;

 lineparm x=0 y=0 slope=1/ lineattrs=(color=green) curvelabel="100%";
 lineparm x=0 y=0 slope=.5/ lineattrs=(color=red) curvelabel="50%";
 lineparm x=0 y=0 slope=.25/ lineattrs=(color=blue) curvelabel="25%";
 title "Zoom coco";
 xaxis grid min=0;
 yaxis grid;
run;

Take a look at this post for more details.

 

Hope this helps!

Dan

Semsem
Fluorite | Level 6

Thank you very much for the code. Sorry for the late answer, I tried the code but I get the error  :

 

ERROR 22-322: Expecting a name.

ERROR 200-322: The symbol is not recognized and will be ignored.

 

Apparently it's because of : attrid="myid"

 

Do you have an idea about what is the problem? 

Thanks in advance

 

Edit :  ok, just in case for someone else, just replace attrid="myid" by attrid=myid

 

Thank you everyone

Jay54
Meteorite | Level 14

Lose the quotes around myid.

Jay54
Meteorite | Level 14

When you have a group variable that has 2 values, the colors come from the Styles's GraphData1-12 color list.  The first group gets GraphData1 (usually blue) and the second will get GraphData2 (often Red).  The colors are based on the style.  Now, if you set the color to black in the syntax, these group colors are overridden by the single color you set.

 

If you want certain specific group colors based on group value, you can use the DiscreteAttrMap code suggested by Dan.  If you just want two different colors, not specifically based on value, set STYLEATTRS statement with Datacolors=(red black).

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
  • 4 replies
  • 2384 views
  • 5 likes
  • 3 in conversation