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

After much struggling I was able to get decent-looking graphs for each series separately, but putting them all on one set of axes with different symbols and/or colors has defeated me. Studio doesn't seem to have the symbol1, symbol2 etc functionality of the main SAS package. I could find no examples that I could adapt, and as usual the SAS documentation isn't friendly for dummies. Here's the code that produced three separate graphs.

 

data meanPower1;
set meanPower;
MeanPlusSD=PowerMean+PowerSD;
MeanMinusSD=PowerMean-PowerSD;
Tweak=0.1;
if TypeOfStretching="Dynamic" then Rep=Rep-Tweak;
if TypeOfStretching="Static" then Rep=Rep+Tweak;

 

title3 "Plot of means and SDs";
title4 "for number of Powerormances >10";
ods graphics / reset imagemap;
proc sgplot data=meanPower1 noautolegend;
   scatter x=Rep y=PowerMean / transparency=0.0 name='Scatter' filledoutlinedmarkers
   markerattrs=(symbol=circlefilled size=10 color=black)
   markerfillattrs=(color=black)
   yerrorupper=MeanPlusSD yerrorlower=MeanMinusSD
   errorbarattrs=(color=black);
   xaxis grid;
   yaxis grid;
   reg x=Rep y=PowerMean / degree=1 nomarkers lineattrs=(color=black thickness=1);
   by TypeOfStretching;
run;
ods graphics / reset;

 

I tried unstarring by TypeOfStretching and adding group=stretching in various places, but it didn't work.

 

Can I really expect my students and colleagues to develop this sort of code as casual SAS Studio users? They can't dial it up from the options tab for sgplot. Without a library of codes they can use for templates, it looks like I will have to tell them to do their plots in Excel and Powerpoint. I'm really sorry to have to say this.  I want SAS Studio to work for plots as well as analyses.

 

Will

1 ACCEPTED SOLUTION
13 REPLIES 13
Reeza
Super User

Have you tried the snippets or the GUI for SAS Studio. Visual Programmer mode offers some options. You can also make your own snippets and task templates so those will probably be developed over time and as needs are indicated. 

 

SG procedures do not use the SYMBOL statements. You may as well forget they exist - they're part of SAS/Graph which us NOT supported in SAS UE. 

Reeza
Super User

To create/manage the marker types and attributes, a feature know as attribute maps is what's used in SAS 9.4+. It allows you to keep colour consistency between plots, since what's symbol1 and symbol2 could change from graph to graph, but attribute maps are set to specific values in your data, not the order of the lines/points.

 

Here's a better post than I can manage with details:

http://blogs.sas.com/content/iml/2016/04/11/attributes-sgplot-style-elements.html

 

Here's what the interface looks like for SAS Studio via the Tasks - it generates the code as well, so you can use that as a starting point. 

I used SASHELP.STOCKS as a starting point.

 

Screen Shot 2016-12-31 at 5.26.43 PM.png

 

Note the Data/Options/Information section in Studio at the top that allow you to set different options for the graph, not symbols though. It does also point you to the relevant parts of the documentation in the Information section. And the code is generated for a starting point. 

 

Screen Shot 2016-12-31 at 5.27.20 PM.png

Screen Shot 2016-12-31 at 5.27.49 PM.png

Reeza
Super User

And use STYLEATTRS to specify symbols/colours.

http://blogs.sas.com/content/graphicallyspeaking/2013/07/14/setting-graph-colors-is-easier-with-sas-...

 

Also, GROUP=TypeOfStretching after the / in your SERIES statement will give you multiple lines per GROUP type.

WillTheKiwi
Pyrite | Level 9

THANK YOU!  See below for the code I am using to produce the attached graph (not quite what I would do for a publication). The only thing I can't do now is change the font, either in the general title or in any of the family=whatever specifications, which I appear to be using correctly in the various ways shown. I have spent hours clicking around the SAS site, to no avail. Presumably it needs something generic, like attrpriority=none, which also took hours to find to get the three datalinepatterns working. The only indication in the LOG is "WARNING: The font <sans-serif> is not available. Albany AMT will be used."

 

Also, is there any way to get the regression lines sitting behind the points? I suspect tweaking in Powerpoint is inevitable.  (I sill don't know how to get it into Powerpoint via the ods.)

 

title3 "Plot of means and SDs";
ods graphics / reset imagemap attrpriority=none;
proc sgplot data=meanPower1 noborder;
styleattrs 
  datacolors=(red green blue)
  datacontrastcolors=(red green blue)
  datalinepatterns=(longdash solid solid)
  datasymbols=(circlefilled squarefilled trianglefilled);
scatter x=Rep y=PowerMean / transparency=0.0 filledoutlinedmarkers
  markerattrs=(size=12)
  yerrorupper=MeanPlusSD yerrorlower=MeanMinusSD
  errorbarattrs=(color=black)
  group=TypeOfStretching;
keylegend /title="Type of stretching:";
xaxis label="Repetition number" labelattrs=(family=Times size=12)
  valueattrs=(family=Times size=12);
yaxis label="Power (W/kg)" labelpos=top labelattrs=(family='Arial Narrow' size=12)
  valueattrs=(family="Times" size=12);
reg x=Rep y=PowerMean / degree=1 nomarkers lineattrs=(thickness=1) group=TypeOfStretching;
*refline 0;
run;
ods graphics / reset;

DanH_sas
SAS Super FREQ

"The only thing I can't do now is change the font, either in the general title or in any of the family=whatever specifications"

 

To adjust the font in the main title, use the standard font syntax in the TITLE statement. As for the FAMILY specifications, I notice in your code you have "Times" both quoted and unquoted. Assuming you're running on a Windows platform, try using "Time New Roman" (in quotes) and see if it works for you.

 

"Also, is there any way to get the regression lines sitting behind the points?"

 

 

Just move the REG statement before the SCATTER statement. The plot statements are drawn in the order they are specified.


Hope this helps!

Dan

WillTheKiwi
Pyrite | Level 9

Dan, thanks for the help. 

 

The suggestion to use the standard font syntax in the TITLE statement worked before a proc print:

title font="Arial Narrow" height=3 "Means and SDs";

I could choose other fonts, including Times and Times New Roman. However this title statement did not allow me to select fonts when it preceded the proc sgplot.  The LOG contained the usual warning: The font <sans-serif> is not available. Albany AMT will be used. Also, height=3 produced a disproportionately large font on thre graph.  I had to use height=2.

 

Also, I could not change fonts in the text within sgplot.  By following links from sgplot I found the family of fonts for sgplot at

http://support.sas.com/documentation/cdl/en/graphref/69717/HTML/default/viewer.htm#n0c8945h7o2kmrn1h...

but they didn't work, as you will see from code beloe and the attached PDF of the plot.

 

I'm trying not to make some angry comment here about the difficulty of doing simple things in SAS, like changing a font. 

 

Finally your suggestion to put the REG statement ahead of the SCATTER statement worked, thank you, but the legend will need cleaning up in Powerpoint. 

 

Here's the current code. Oh, by the way, there is apparently no control over the size of the caps of the error bars in sgplot, so I have had to make everything else larger so that the caps don't look ugly. What I've ended up with there is about right for reducing the size of the whole plot in Powerpoint (before ungrouping) to make a figure for publication, and to increase the size somewhat to make a figure for a slide.  The blue color fill in the square symbols does not completely fill the squares when the graph is ungrouped.  I doubt whether direct output to Powerpoint will solve this problem. (At the moment ungrouping after direct output results in complete loss of the figure. I am still waiting for a solution to this problem.)

 

title font="GERMANBI" height=2 "Means and SDs";
ods graphics / reset width=16cm height=18cm imagemap attrpriority=none;
proc sgplot data=meanPower1 noborder;
styleattrs 
  datacolors=(white blue red)
  datalinepatterns=(solid solid solid)
  datacontrastcolors=(black black black)
  datasymbols=(circlefilled squarefilled diamondfilled);
reg x=Rep y=PowerMean / degree=1 nomarkers lineattrs=(thickness=0.5) group=TypeOfStretching;
scatter x=Rep y=PowerMean / transparency=0.0 filledoutlinedmarkers
  markerattrs=(size=20)
  yerrorupper=MeanPlusSD yerrorlower=MeanMinusSD
  errorbarattrs=(color=black)
  group=TypeOfStretching;
keylegend /title="Type of stretching:" noborder titleattrs=(size=16 family="GERMAN") valueattrs=(size=16);
xaxis label="Repetition number" labelattrs=(family="SWISSBI" size=16)
  valueattrs=(family="Times New Roman" size=16);
yaxis label="Power (W/kg)" labelpos=top labelattrs=(family="Arial Narrow" size=16)
  valueattrs=(family="Times" size=16);
*refline 0;
run;
ods graphics / reset;

DanH_sas
SAS Super FREQ

In regards to your legend cleanup, you can control the legend content programmatically by assigning a name to the plots you want in the legend and using those names on the KEYLEGEND statement. For example, if you only wanted the SCATTER plot in the legend:

 

scatter x=Rep y=PowerMean / transparency=0.0 filledoutlinedmarkers name="myScatter"
  markerattrs=(size=20)
  yerrorupper=MeanPlusSD yerrorlower=MeanMinusSD
  errorbarattrs=(color=black)
  group=TypeOfStretching;
keylegend "myScatter" / title="Type of stretching:" noborder titleattrs=(size=16 family="GERMAN") valueattrs=(size=16);

Rick_SAS
SAS Super FREQ

Can you please claify how you are running SAS?

1. SAS Univerisity Edition 

2. SAS installed locally on your PC, accessed via SAS Studio interface

3. SAS installed on a remote server, accessed via SAS Studio interface

4. SAS On-Demand for Academics (SODA)

5. Other (please specify)

 

WillTheKiwi
Pyrite | Level 9

*Can you please claify how you are running SAS?

Sure. SAS Univerisity Edition, installed on PC, Windows 7/Office 2010/Internet Explorer 11.0.35. I have been using SAS for ~30 years, by the way.

 

Will

Rick_SAS
SAS Super FREQ

The document that describes the limitations of SAS University Edition contains a lot of important information. In particular, the doc says 

  • Only these fonts are supported: Albany AMT Regular, Albany AMT Bold, Arial Unicode MS, and Cumberland AMT Regular.

 

WillTheKiwi
Pyrite | Level 9

Thanks, and I apologize for not finding this in the documentation.  It's not entirely true, because I could get all sorts of fonts with proc print. Anyway, it underscores the need to clean up graphs in Powerpoint.

 

I will be running a workshop on SAS Univeristy Edition with some colleagues in China.  At first we thought a Chinese language version was available, and according to that documentation it is, but apparently he cold download only the English version.  Any help on that?

 

Will

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