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

Hi all,

Im trying to create a scatter plot with Sgpanel but I can`t figure how to customize it with my Costat variable.
Costat variable basicaly tells me if the company is Bankrupt(=1) or Not (=0). I would like to see the Non banrupt companies in green and the shape being circles where as the Bankrupt companies would be red stars.

Here is my actual code for now :

proc sgpanel data= analyse_all;
panelby H / rows= 1;
scatter X= X5 Y= X1;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

Here's some code that should do what you're asking (except I use a triangle instead of a star)...

 

%let name=sgpanel;

/*
Set your current-working-directory (to read/write files), if you need to ...
%let rc=%sysfunc(dlgcdir('c:\someplace\public_html'));
*/
filename odsout '.';

ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm" style=htmlblue;
ods graphics / imagemap tipmax=25000 imagefmt=png imagename="&name"
width=800px height=600px noborder;

libname my_data 'u:\web\proj\pabster';
data analyse_all; set my_data.data;
run;

/* user-defined format for text that prints in legend */
proc format;
value $status
"0" = "Not Bankrupt"
"1" = "Bankrupt"
;
run;

/* attribute map, for color & shape */
data myattrmap;
length id value markercolor markersymbol $20;
id='myid';
value='Not Bankrupt'; markersize=12; markercolor='green'; markersymbol='circle'; output;
value='Bankrupt'; markersize=12; markercolor='red'; markersymbol='triangle'; output;
run;

title1 h=16pt "Banking Graph";
proc sgpanel data=analyse_all dattrmap=myattrmap;
format costat $status.;
panelby H / rows= 1;
scatter X= X5 Y= X1 / group=costat attrid=myid;
keylegend / position=bottom fillheight=11pt noborder
title="" valueattrs=(color=gray33 size=11pt weight=bold);
run;

quit;
ODS HTML CLOSE;
ODS LISTING;

 

banking_graph.png

View solution in original post

4 REPLIES 4
Reeza
Super User

Try adding a GROUP = to your SCATTER statement to create different symbols. To customize the shapes you'll need to specify the attributes you want using the STYLEATTRS statement

 

GROUP= documentation reference

https://documentation.sas.com/?docsetId=grstatproc&docsetTarget=n06qalr0ymoddkn17finxbpmv6e8.htm&doc...

 

STYLEATTRS reference (datasymbols and datacolor)

https://documentation.sas.com/?docsetId=grstatproc&docsetVersion=9.4&docsetTarget=p0qva1ws6twy5xn0zd...

 


@Pabster wrote:

Hi all,

Im trying to create a scatter plot with Sgpanel but I can`t figure how to customize it with my Costat variable.
Costat variable basicaly tells me if the company is Bankrupt(=1) or Not (=0). I would like to see the Non banrupt companies in green and the shape being circles where as the Bankrupt companies would be red stars.

Here is my actual code for now :

proc sgpanel data= analyse_all;
panelby H / rows= 1;
scatter X= X5 Y= X1;
run;

 


 

DanH_sas
SAS Super FREQ
In addition to GROUP option suggested by @Reeza, you might want to consider using a discrete attributes map, since you want to assign specific attributes to specific group values. You will not need the STYLEATTRS statement in that case.

Hope this helps!
Dan
GraphGuy
Meteorite | Level 14

Here's some code that should do what you're asking (except I use a triangle instead of a star)...

 

%let name=sgpanel;

/*
Set your current-working-directory (to read/write files), if you need to ...
%let rc=%sysfunc(dlgcdir('c:\someplace\public_html'));
*/
filename odsout '.';

ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm" style=htmlblue;
ods graphics / imagemap tipmax=25000 imagefmt=png imagename="&name"
width=800px height=600px noborder;

libname my_data 'u:\web\proj\pabster';
data analyse_all; set my_data.data;
run;

/* user-defined format for text that prints in legend */
proc format;
value $status
"0" = "Not Bankrupt"
"1" = "Bankrupt"
;
run;

/* attribute map, for color & shape */
data myattrmap;
length id value markercolor markersymbol $20;
id='myid';
value='Not Bankrupt'; markersize=12; markercolor='green'; markersymbol='circle'; output;
value='Bankrupt'; markersize=12; markercolor='red'; markersymbol='triangle'; output;
run;

title1 h=16pt "Banking Graph";
proc sgpanel data=analyse_all dattrmap=myattrmap;
format costat $status.;
panelby H / rows= 1;
scatter X= X5 Y= X1 / group=costat attrid=myid;
keylegend / position=bottom fillheight=11pt noborder
title="" valueattrs=(color=gray33 size=11pt weight=bold);
run;

quit;
ODS HTML CLOSE;
ODS LISTING;

 

banking_graph.png

Pabster
Obsidian | Level 7
Thanks!!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 980 views
  • 2 likes
  • 4 in conversation