Data visualization with SAS programming

Proc SGSCATTER options with ungrouped data

Reply
New Contributor
Posts: 4

Proc SGSCATTER options with ungrouped data

I am attempting to create a single graph showing the average EMS transports by hospital using Proc SGSCATTER Compare.  Unfortunately, my data on hospitals is ungrouped (each hospital represents its own column) and as such, I cannot seem to find a way to assign a different color to each hospital series.  This is my current syntax but I am aware that this will not work unless my compare statement uses the GROUP option.  Is there any way around this to get the layout I want?  Thanks in advance for any suggestions.

proc template;                                                                                                                         

define style styles.custom;                                                                                                         

parent=styles.default;                                                                                                               

style GraphData1 from GraphData1 /                                                                                                 

contrastcolor=purple ;                                                                            

style GraphData2 from GraphData2 /                                                                                                 

contrastcolor=orange ;                                                                            

style GraphData3 from GraphData3 /                                                                                                 

contrastcolor=blue ;

style GraphData4 from GraphData4 /                                                                                                 

contrastcolor=red ;                                                                            

style GraphData5 from GraphData5 /                                                                                                 

contrastcolor=green ;                                                                            

style GraphData6 from GraphData6 /                                                                                                 

contrastcolor=black ;

style GraphData7 from GraphData7 /                                                                                                 

contrastcolor=rose ;                                                                            

style GraphData8 from GraphData8 /                                                                                                 

contrastcolor=gray ;                                                                            

style GraphData9 from GraphData9 /                                                                                                 

contrastcolor=yellow ;

end;                                                                                                                                 

ods html file='' style=Custom;

proc sgscatter data=HS.transports;

title "Arrivals Jan. 2011-Dec. 2013";

compare y= (Hosp1 Hosp2 Hosp3 Hosp4 Hosp5 Hosp6 Hosp7 Hosp8 Hosp9 x=servicedate /

     join=(lineattrs=(pattern=solid));run;

ods html close;

SAS Super FREQ
Posts: 925

Re: Proc SGSCATTER options with ungrouped data

For now, you best option is to transpose your data such that you have a column of hospital names and use PROC SGPANEL to create the graph. Here is the SGPANEL code that should give you the result you want:

/* Each cell will have the hospital name */

proc sgpanel data=HS_transports;

panelby hospitals / onepanel;

series x=servicedate y=arrivals / markers lineattrs=(pattern=solid);

run;

- or -

/* Add some color as well */

proc sgpanel data=HS_transports noautolegend;

panelby hospitals / onepanel;

series x=servicedate y=arrivals / markers group=hospitals lineattrs=(pattern=solid);

run;

Hope this helps!

Dan

New Contributor
Posts: 4

Re: Proc SGSCATTER options with ungrouped data

DanH, I can't thank you enough.  This worked beautifully!  Liz

Ask a Question
Discussion stats
  • 2 replies
  • 305 views
  • 0 likes
  • 2 in conversation