Help using Base SAS procedures

SGPlot formatting questions

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

SGPlot formatting questions

Hello, I am new to the SAS forum.  I am looking for some assistance in formatting a couple of scatterplots for my M.Sc thesis.  I am using SAS 9,3

I have created the scatterplot and trendlines in Proc SGPlot, however there are two minor issues that I need to resolve

1) The data is grouped, and in the legend that is created the group names (which are numbers) get truncated using scientific notation.  Is there a way to get SG plot to show the entire number in the Legend?  The entire number is needed for the legend to make sense.

2) For the Axis titles my units are in Square meters.  Is it possible to incorporate superscripts into the axis titles?

I would appreciate any feedback I can get.


Accepted Solutions
Solution
‎05-30-2014 01:13 PM
Respected Advisor
Posts: 4,654

Re: SGPlot formatting questions

Hi Dan,

The first part of my code was simply there to create example data for plotting, you can ignore it. All you need to do is :

proc sgplot data=Chapter2AspenNLinOut;

scatter x=LiDARGapArea y=ExpandedGapArea / group=Polygon;

series x=LiDARGapArea y=Pred / group=Polygon;

yaxis label='Expanded Gap Area (m²)';

xaxis label='LiDAR Gap Area (m²)';

format Polygon best20.;

run;

PG

PG

View solution in original post


All Replies
Respected Advisor
Posts: 4,654

Re: SGPlot formatting questions

1) Use an explicit format for your group variable

2) Use Unicode character '00B2' which represents superscript 2 (you might be able to cut and paste it from the code below)

data test;

call streaminit(76576);

do group = 121212121212211, 63565345534556;

    do x = 1 to 12;

        y = sum(y, rand('Normal'));

        output;

        end;

    end;

run;

title;

proc sgplot data=test;

format group best20.;

series x=x y=y / group=group;

yaxis label="Y (m²)";

run;

SGPlot3.png

PG

PG
New Contributor
Posts: 4

Re: SGPlot formatting questions

Thanks for the prompt response,

I have attempted the "do" statement and I think my inexperience is showing.  When I included a do statement the log stated that I needed an end statement as well. Here is the code I was using,

proc nlin data=Aspen  NLINMEASURES plots(stats=all)=(diagnostics) ;

ods rtf file="D:\Chapter2DataTables\AspenPowerFunction.rtf";

  parms a=30 b=0.4;

    model Y=a*X**b;

    by polygon;

  do group = 6796103, 6886289; tried to add the do statement here...

  Output Out=Chapter2.AspenNlinOut Predicted=pred;

run;

ods rtf close;

Title test;

proc sgplot data=Chapter2.AspenNLinOUt;

Scatter x=LiDARGapArea y=ExpandedGapArea / group=Polygon;

yaxis label='Expanded Gap Area (m²)';

xaxis label='LiDAR Gap Area (m²)';

series x=LiDARGapArea y=Pred / group=Polygon;

run;

Solution
‎05-30-2014 01:13 PM
Respected Advisor
Posts: 4,654

Re: SGPlot formatting questions

Hi Dan,

The first part of my code was simply there to create example data for plotting, you can ignore it. All you need to do is :

proc sgplot data=Chapter2AspenNLinOut;

scatter x=LiDARGapArea y=ExpandedGapArea / group=Polygon;

series x=LiDARGapArea y=Pred / group=Polygon;

yaxis label='Expanded Gap Area (m²)';

xaxis label='LiDAR Gap Area (m²)';

format Polygon best20.;

run;

PG

PG
New Contributor
Posts: 4

Re: SGPlot formatting questions

The format statement solved it.  Thanks very much for the assistance.

New Contributor
Posts: 4

Re: SGPlot formatting questions

Thanks again for the assistance before.

I have been asked to modify the scatter plots a little more.  The current plots create an output which is distinguished only by color.  I have been asked to change up one set of data points so that the markers and series line are different (maybe change them to closed circles and a dashed line).  With the data sets being separated using the group statements I am not sure how to modify them to change only one set of markers.  Any ideas would be appreciated.  I haven't seen anything in the other posts in this forum yet.

proc sgplot data=Chapter2.AspenNLinOUt;

Scatter x=LiDARGapArea y=ExpandedGapArea / group=Polygon;

yaxis label='Expanded Gap Area (m²)';

xaxis label='LiDAR Gap Area (m²)';

series x=LiDARGapArea y=Pred / group=Polygon markerattrs=;

format Polygon best20.;

run;

Thanks again for the assistance.

Respected Advisor
Posts: 4,654

Re: SGPlot formatting questions

You should change the style associated with your ODS destination. By default the style is HTMLBLUE which only changes colors among the first 12 groups. The alternate style HTMLBLUECML (CML: Color-Marker-Line) changes every aspect from one group to the other. Add a statement such as

ODS HTML style=HTMLBLUECML;

before proc sgplot to request the alternate style. Also, remove the markerattrs= request from the series statement.

PG

PG
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 550 views
  • 3 likes
  • 2 in conversation