/* Program for "Scatter plots with logarithmic axes...and how to handle zeros in the data" http://blogs.sas.com/content/iml/2014/07/09/scatter-plots-with-log-axes/ by Rick Wicklin */ data Comments; label Comment = "Number of Original Comments" Response = "Number of Responses"; input Commenter $20. Total Comment Response; nickName = substr(Commenter, 1, find(Commenter," ")); if Total>30 then truncName = nickName; datalines; Chris Hemedinger 653 92 561 Rick Wicklin 501 74 427 Robert Allison 247 25 222 Sanjay Matange 148 11 137 Michelle Homes 140 128 12 Angela Hall 122 41 81 Tricia Aanderud 115 99 16 Waynette Tubbs 83 17 66 John Balla 59 9 50 Shelly Goodin 52 25 27 Charu Shankar 45 11 34 Mark Jordan 45 3 42 Peter Flom 42 38 4 Alison Bolen 38 11 27 Quentin 35 31 4 Sunil Gupta 34 32 2 Mike Clayton 34 34 0 Ian Wakeling 33 27 6 Phil Simon 31 28 3 Divyesh Dave 28 27 1 Jim Harris 28 14 14 Lisa Horwitz 27 1 26 charu 25 8 17 LeRoy Bessler 24 24 0 Mike Gilliland 24 8 16 Christina Harvey 23 4 19 Faye Merrideth 23 20 3 Peter Lancashire 22 19 3 Anonymous 22 22 0 Michael A. Raithel 21 10 11 Paul Homes 20 20 0 Chris 19 18 1 Peter 19 15 4 Kriss Harris 19 16 3 Stefan Hauck 18 15 3 Bernd Günter 18 18 0 Michele Reister 17 3 14 Bradley Jones 17 0 17 Xan Gregg 17 5 12 jaap karman 16 15 1 Bob 15 12 3 Dylan Jones 15 14 1 Mark Stevens 15 2 13 Daniel Valente 14 3 11 Jared Prins 14 13 1 AnnMaria 14 14 0 James Marcus 13 9 4 Kathy Council 13 3 10 Clark Abrahams 13 1 12 Cat Truxillo 13 12 1 ; ods graphics / reset; /* 1. Show the standard scatter plot */ ods graphics / width=800 height=800; title "Comments and Responses on blogs.sas.com"; proc sgplot data=Comments noautolegend; scatter x=Comment y=Response / datalabel=TruncName; lineparm x=0 y=0 slope=1; yaxis grid offsetmin=0.05; xaxis grid; run; proc sgplot data=Comments; histogram Response / binstart=10 binwidth=20; run; /* 2. Try a log-log plot... can't do it because some data are 0! */ /* xaxis grid type=log; NOTE: Log axis cannot support zero or negative values in the data range. The axis type will be changed to LINEAR. */ /* 3. restrict to positive values */ ods graphics / width=600 height=800; title "Automatic Log Transformation"; title2 "Comment>0 and Response>0"; proc sgplot data=Comments; where Comment>0 & Response > 0; scatter x=Comment y=Response / datalabel=NickName; xaxis grid type=log logstyle=logexpand minor offsetmin=0.01; yaxis grid type=log logstyle=logexpand minor offsetmin=0.05; run; title2; /* print the individuals who were dropped */ title "Dropped individuals"; proc print data=Comments; where Comment=0 | Response=0; var NickName Comment Response; run; /* The LINEPARM statement does not work for log-log axes. However, you can use VECTOR stmt in a creative way to add the diagonal reference line. */ /* 4. use x--> log(x+1) transformation */ data LogComments; set Comments; label logCommentP1 = "log10(1 + Number of Original Comments)" logResponseP1 = "log10(1 + Number of Responses)"; logCommentP1 = log10(1 + Comment); logResponseP1 = log10(1 + Response); run; ods graphics / imagemap=ON; title "Custom Log Transformation"; proc sgplot data=LogComments noautolegend; scatter x=logCommentP1 y=logResponseP1 / datalabel=NickName tip=(Comment Response Total); lineparm x=0 y=0 slope=1; xaxis grid offsetmin=0.01; yaxis grid offsetmin=0.05 offsetmax=0.05; run;