BookmarkSubscribeRSS Feed
Almutairi
Fluorite | Level 6

Hi,

I am trying to submit a paper to a journal which prints graphs in black. The following code gives two nonblack colors to the overlapped curve lines of the two graphs. I would like to know how to adjust this code so I can change (1) one of the curve lines to a dotted curve, (2) change the color of the two histograms to black, one solid and one gradient, and (3) create a white line divides each binwidth, please.


title "Distributions of scaled earnings and earnings before abnormal CFO";
proc sgplot data=compu_graph_EBACFO;
histogram Lagearnings1 / binwidth=0.01 binstart= -0.25 showbins transparency=0.4
name="Scaled earnings" legendlabel="Scaled earnings";
histogram EB_ACFO / binwidth=0.01 binstart= -0.25 showbins transparency=0.5
name="Earnings before abnormal CFO" legendlabel="Earnings before abnormal CFO";
density Lagearnings1 / type=kernel lineattrs=GraphData1; /* optional */
density EB_ACFO / type=kernel lineattrs=GraphData2; /* optional */
xaxis values= (-0.25 to +0.25 by 0.01);
xaxis label="Interval width (0.01)" min=-0.25;
keylegend "Scaled earnings" "Earnings before abnormal CFO" / across=1 position=TopRight location=Inside;
run;

7 REPLIES 7
Rick_SAS
SAS Super FREQ

make your life simple and use the Journal style. Here is an overview of Statistical Graphics using ODS.

Here is the doc for styles and the JOURNAL family of styles.

 

Start by putting 

ods [DESTINATION] style=Journal;

before your call to PROC SGPLOT and see how it looks.

For example, 

ods html style=Journal;

ods latex style=Journal;

etc

Almutairi
Fluorite | Level 6

Perfect. Thank u Rick as always. 

DanH_sas
SAS Super FREQ

First of all, you might want to check out your output if you run it using STYLE=JOURNAL2 on your ODS statement; however, the histogram will no be filled in that case.

 

To get what you requested, try the modified code below. I'm not sure it the histograms will be like you want. Just let us know:

 

title "Distributions of scaled earnings and earnings before abnormal CFO";
proc sgplot data=compu_graph_EBACFO;
histogram Lagearnings1 / binwidth=0.01 binstart= -0.25 showbins transparency=0.4 fillattrs=(color=black)
name="Scaled earnings" legendlabel="Scaled earnings";
histogram EB_ACFO / binwidth=0.01 binstart= -0.25 showbins transparency=0.5 fillattrs=(color=black) outlineattrs=(color=white)
name="Earnings before abnormal CFO" legendlabel="Earnings before abnormal CFO";
density Lagearnings1 / type=kernel lineattrs=(color=black pattern=solid)
density EB_ACFO / type=kernel lineattrs=(color=black pattern=dot)
xaxis values= (-0.25 to +0.25 by 0.01);
xaxis label="Interval width (0.01)" min=-0.25;
keylegend "Scaled earnings" "Earnings before abnormal CFO" / across=1 position=TopRight location=Inside;
run;

Hope this helps!

Dan

Almutairi
Fluorite | Level 6

Thank you Dan for your quick response. I ran the code but I encountered some errors. See the attachment plz.

 

 

 

 

DanH_sas
SAS Super FREQ

My apologies. OUTLINEATTR control for HISTOGRAMS s available in GTL, but not currently in the SG procedures. Also, it should have been PATTERN in the LINEATTRS option, not LINEPATTERN.

 

If you want to use SGPLOT, and still get your white outlines, you'll have to make a a small ODS style that inherits from a style like JOURNAL2. I'll create one and post back.

 

Thanks!
Dan

DanH_sas
SAS Super FREQ

Here's a simple example using the new style. You can adapt it to your original code by just adding the LINEATTRS options to your DENSITY statements.

 

Thanks!

Dan

 

The SGPlot Procedure

 

proc template;
define style styles.MyJournal;
parent=styles.journal;

style GraphData1 from GraphData1 /
      color = cx000000;
style GraphData2 from GraphData2 /
      color = cx000000;
style GraphOutlines from GraphOutlines /
      contrastcolor = cxFFFFFF;
end;
run;

ods html style=myjournal;
proc sgplot data=sashelp.heart;
histogram weight / transparency=0.4;
histogram cholesterol / transparency=0.4;
density weight / type=kernel lineattrs=(pattern=solid);
density cholesterol / type=kernel lineattrs=(pattern=dot);
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 7 replies
  • 1824 views
  • 2 likes
  • 3 in conversation