5 Reasons to write your first SAS Press book

Editor's note: This series of blogs addresses the questions we are most frequently asked at SAS Press!

Ever thought about writing your own SAS or JMP book? Here are a few reasons why writing a SAS Press book can be a fantastic career move!

1.      Your book establishes you as an expert and enhances your credibility

Being recognized as a subject-matter expert or thought leader is beneficial if you’re looking to gain more media attention for yourself. If you see yourself as more of a thought leader than a programmer, SAS Press has partnered with Wiley for the Wiley and SAS Business Series to publish thought leadership titles and high-level business concept books.

write-a-book-with-sas01

Mike Gilliland and Udo Sglavo with their Wiley Business Series title, Business Forecasting: Practical Problems and Solutions

2.      Your book helps promote and nurture your digital self

Consider a book as a launch pad for a whole host of social media and web credibility opportunities. We have social media specialists to drive the content, and with it your digital persona, helping nurture and develop your professional digital self––keeping it fresh and in the public eye.

3.      Your book can be your business card.

While you’re working at the office, your book can be out working as well, helping you grow your audience, teaching people, and building your reputation as an authority in your field. Use your book to start or further conversations with new or existing SAS customers, or like-minded professionals. At meetings and conferences, you can use your book as your business card! Your book can lead to more career opportunities.A book can really enhance a career by generating new opportunities and enhancing existing ones. Whether it’s speaking engagements, teaching classes, or webinars, everyone wants the person who “wrote the book” to come speak to them firsthand!

4.      Your book royalties provide additional income

You’ll always make far more in opportunities that a book can bring than in the book itself (unless you have a national bestseller), but you can still count on some income from the sales of the book. Via our SAS bookstore, national resellers, and global booksellers, your book will reach a worldwide audience in print and e-book formats!

5.      Your book can help other SAS and JMP users

The biggest reason to write a book is that SAS books enhance the skills and careers of SAS users. Sharing your knowledge helps them grow!

write-a-book-with-sas02

In the classroom with Jane Eslinger’s The SAS® Programmer’s PROC REPORT Handbook

The first step in writing a book is deciding to take that first leap of faith! Watch this short video for helpful advice from first-time SAS Press authors to anyone thinking about writing their first book.

Learn more about how to submit a book proposal.

Too Busy to Write? Review Instead!

If you have technical and teaching abilities but are too busy to write a book, we are always looking for qualified technical reviewers to help with our book development process! Reviewers receive a copy of the book when it’s published, book credit to be used in the SAS Store, and much gratitude from SAS and SAS Press authors for your help! Learn more about how to review one of our books.

 

Post a Comment

My top 10 graph blog posts of 2016!

When I was a kid, I always looked forward to Casey Kasem's American Top 40 song countdown at the end of the year. Did I listen to check whether my favorite songs had made the list, or to critique how well the people making the list had done in picking the 'right' songs? Of course, it was probably a little of both, hahaha!

This year I've written over 80 blog posts, and I decided to make a list of the 10 I think are the best! These aren't necessarily the ones that had the most views, but rather the ones I think had really good/innovative/clever graphs of interesting data. I really enjoyed writing these 10, and I hope you enjoyed (or will enjoy) reading them...

I like to include a random somewhat-related photo with my blogs, and this time I asked my friends if they had a picture of a ribbon/medal/trophy they had won. I found out that my friends are really good at a big variety of things ... and the one I decided to share is from my co-worker Mark, who was a body-builder back in the day. Here's one of the trophies he won - 1996 NPC Sacramento Bodybuilding Championship, overall winner, Masters Division (and yes, he looked exactly like the guy in the trophy!)

mark_trophy

And now, here are my top 10 blog posts, in chronological order. You can click the blog titles or the thumbnails to go to the actual blog posts ...

 

Timeline of Supreme Court Justices

scotus

This was a timely topic, since one of the justices recently died and the president will be appointing a new one. I really like the graphical representation I came up with, because it shows the balance between the liberal and conservative justices. It will be interesting to see if the balance shifts, or stays the same, after the new justice is appointed.

 

 

 

How to graph NBA data with SAS

nbaAfter the Moneyball movie came out a few years ago, sports teams have realized that analytics can give them a huge advantage. Historically, baseball has probably been the sport with the most data collected ... but in recent years, other sports like football and baseball have been increasing their data collection by leaps & bounds. The amount of data could be overwhelming, but a good graph can help you get a handle on thousands of data points on a single page. This post shows how to use SAS to create a custom graph that looks like a basketball court, and plot all the shots on it.

 

 

A graph fit for a Prince

princePrince's songs were really popular during my formative years, and I was sad to hear that he had died. Looking back, I was wondering when all his songs had been released, and plotting the data on a time-axis seemed like a good way to visualize the data. If you're a Prince fan, you'll want to check this one out - it's a cool discography, and also a nice tribute to Prince, The Artist!

 

 

 

 

What you see is what you get ... maybe!

koffkaThis is one of my most fun blog posts. I created several mind-bending examples, showing both the flexibility of SAS, and how the eyes and the brain don't always reach the same conclusion. The examples range from the classic Koffka rings, to a more obscure color-name test, to my own version of a viral Facebook trick graph that left a lot of people shaking their heads (literally!)

 

 

 

 

The big fat truth about the US weight problem

obesityIn the last couple of decades, the US has seen a dramatic increase in the number of overweight and obese people. I found a graph that tried to show this shift, but there were several problems with it. Therefore I demonstrated step-by-step how I thought it should be changed, and came up with (what I think) is a graph that shows the data really well.

 

 

Pokémon: Gotta graph 'em all!

pokemonThe new Pokémon game became really popular this year, after it came out as a smartphone app. Therefore when I found out that there was a huge collection of data available, I knew I had to graph it. In this post, I show several different ways to graph the various kinds of data. Much to my surprise, my Pokémon blog(s) even got a mention in the local newspaper. Even if you can't catch 'em all, you can still catch this blog post and find out how to graph 'em all!

 

 

 

 

91% of the US didn't vote for Hillary or Trump!

prelimWith this being a major election year, there was plenty of political data to graph. This blog post focuses on an aspect of the election that I hadn't really given much thought to before -- the Primary elections, where each party selects their presidential candidate. Many people complained that they didn't like either of the two candidates that were in the final election (Hillary & Trump) ... but according to this graph, it is quite likely that those people didn't even vote in the Primaries (and therefore it's their own fault!).

 

 

 

 

 

If we didn't start the fire, then who did?

fireI really like graphing data that is related to pop culture, and especially when it is data from 'my generation.' This example takes a Billy Joel song (We Didn't Start the Fire) that was popular when I was in school, and plots all the events mentioned in the song on a timeline graph. But not just any old timeline graph ... this one is shaped like a combination of an old-school vinyl record, and the Tempest video game from the 1980s. I hope you enjoy this graph as much as I enjoyed creating it!

 

 

 

 

 

A statistical crossword puzzle to exercise your brain

crosswordCrosswords puzzles were in the news this year, as clever analysts found that many of the puzzles were not actually unique, but copies (or partial copies) of ones already published in the past. I decided to create my own crossword puzzle, using words from statistics and analytics. It was a fun project, and also demonstrates that SAS software is flexible enough to do just about anything!

 

 

 

 

 

 

Which drinks have the most, and least, caffeine?

caffeineComputer people seem to have a reputation for drinking a lot of caffeine. I don't know if that reputation is totally true, but I can say that my favorite and most often used perk at SAS is the free soda machine in the break room, LOL! Therefore, when I found some caffeine data, I knew that I had to share it with my blog readers ... and what better way to do that, than in graphical form!

 

 

 

 

 

I hope you've enjoyed my 'top 10' list! If you'd like to see these 10 in the context of the other 80 blog posts I wrote in 2016, here's a graph showing them all. You can click the image below to see the interactive version of the graph, with mouse-over text (showing the titles) and drill down links (which go to the actual blog posts).

my_blogs_2016

 

So, how well did I do picking the right blog posts for the top 10? If I left out any that you feel should have made the list, feel free to mention them in a comment!

 

Post a Comment

Forecasting your next breakup!

Has anyone ever broken up with you, and left you thinking "Wow, I didn't see that coming!" In hindsight, maybe you could have seen it coming. At least from a statistical perspective. Let's dive into this topic with some lighthearted discussion, and plot some Facebook data...

When it comes to breaking up, there's a guy-talk joke that you should break up right before Thanksgiving, and then wait to start dating again until after Valentine's -- that way you don't have to go to all the family dinners with your girlfriend's family, and you get out of buying her several gifts, etc.

An interesting NPR article mentions another twist on the phenomenon of breaking up during the Thanksgiving holiday, calling it the "turkey drop season." No, a turkey drop isn't like the possum drop they do in Clay's Corner, NC for the New Year's Eve celebration! NPR explains that "The turkey drop is that holiday breakup season where all the college students return home for their first major vacation, and everyone breaks up" (this is generally freshmen who have been in college for a couple of months, and finally decide to break off the long-distance relationship with their pre-college sweetheart).

These were interesting theories (or urban legends?), but I wondered if real-world data would confirm, or refute, them? And what other breakup trends might the data show? ...

Several years ago, David McCandless teamed up with Lee Byron to create a graph of real data showing the timing of breakups throughout the year (see his book The Visual Miscellaneum, p. 179). The data came from Facebook's 2008 Lexicon service, which allowed you to specify keywords & phrases, and provided you with the frequency of those words in Facebook status updates over time. There's no explanatory text in his book (only the graph), but an article on nydailynews.com explains that the data is based on 10,000 Facebook users in 2008. Here's the graph:

breakup_graph_orig

It was a decent graph, but a little difficult to determine exactly what date peaks occurred on. Also, some of the labels ran together (Spring Break & Valentine's), and I think the extra text such as "spring clean" and "too cruel" cluttered the graph, without adding any additional insight.

So I decided to create my own version, using SAS Software. I wouldn't find McCandless' raw data anywhere, and Facebook no longer offers the free Lexicon service therefore I couldn't generate fresh data for the current year. Therefore I painstakingly went through his graph one point at a time, and estimated & transcribed a data value for each day of the year (yes, it was very tedious!) I then created the following graph:

breakup_graph

Here are some of my changes & improvements:

  • I added a better title, that better explains the data.
  • I added grid lines at the beginning & end of each month, so it's easier to estimate the dates.
  • I added grid lines along the y-axis, so you can more easily see if the data line is increasing or decreasing.
  • I shortened the label text, and simplified the lines connecting the text to the graph.
  • I labeled a few extra points along the graph, such as 'Superbowl' and 'Election Day'.
  • I added mouse-over text at each point along the plot, so you can easily determine the date at the peaks and valleys of the data line (click the image/snapshot above to see the interactive version with mouse-over text).

The graph does seem to concur that there are a lot of breakups between Thanksgiving and Christmas ... but it also shows a lot of breakups in February & March. It's an interesting graph, but for me it raises more questions than it answers. For example:

  • What age group were the Facebook users? I assume that in 2008, Facebook would have tended to have more younger users than today.
  • It would be interesting to see separate graphs for high school students, college students, and adults not in school.
  • What countries were the Facebook users in? I assume it was probably mostly US, but that might not be a valid assumption.
  • Is it possible that some of these were "false positives" where someone made a post about a celebrity breakup?
  • I assume the Lexicon keyword search was based on text posted to the users' wall, but it would have also been interesting to graph the Relationship Status (single, in a relationship, etc). In particular, it would be interesting to see what % of the users are single on each day throughout the year.

What other questions or suggestions do you have, for analyzing breakup data? Feel free to leave a comment!

 

Post a Comment

Ron Cody’s Tips on Using SAS University Edition

tips-on-using-sas-university-editionI often wonder how many people see the word "University" in the title "SAS University Edition" and think you have to be a university student to download this software. Please help me spread the word: Anyone can download the University Edition (as long as you’re using it for learning purposes) and the best part, it's FREE.

I just returned from the South Central SAS User Group meeting (in San Antonio) where I attended a talk by Ryan Lafler (Kirk's son). One of the first questions from the audience was "is the University Edition a watered-down, restricted version of SAS?"  The answer is no.  The SAS University Edition – let’s call it UE - is a complete version of SAS that even includes SAS Stat, SAS IML, and the Access product.  Is there a catch? Just one – you are not supposed to use the SAS University Edition for commercial purposes.

I could go on and on about how awesome it is that SAS offers this option for learners, but the title of this blog includes the word "Tips" so I better get going and tell you a few. First of all, to obtain your free copy of SAS, click here.

...or, even easier, just type "SAS University Edition" in Google or whatever search engine you use.

Here's another good tip: If you are using UE to learn SAS, follow the installation instructions and create a folder on your hard drive called "c:\SASUniversityEdition\Myfolders" (or the appropriate form on Apple or Linux) and place your data (such as Excel Workbooks) there.  Here's the reason:  The virtual environment is running Linux, where file naming conventions are not the same as those on Microsoft or Apple.  So, to communicate between your "real" computer and the "virtual" computer, you must set up a shared folder. (There are step-by-step instructions in the installation guides.) I should also mention that my two books, Introduction to SAS University Edition and Biostatistics by Example Using SAS Studio show you screen shots of every step in setting up UE and SAS Studio.

The last piece of information I want to share with you is how easy it is to use the Import Utility. It's even better than the Import Wizard that’s part of the Display Manager. You can import data from just about any source (Excel, Access, etc.) and for most files, you don't even have to specify the data source—the Import Utility will look at the file extension and, if it is one it recognizes (.xls or .xlsx, for example) it will perform the conversion automatically.

OK, a bonus tip. If you’re slightly older (such as myself), find a young person to give you a hand when you install the University Edition and SAS Studio! They can probably do it in half the time!

Post a Comment

Editing the SAS Code Generated by the One-Way Frequencies Statistics Task

one-way-frequencies-statsitics-task-cody-bookSuppose you are using SAS Studio (perhaps with the University Edition) and the statistical task you need to perform is not a supported option or feature in SAS.  I know that sounds almost impossible because the statistical tasks in SAS Studio are so awesome.  But, just in case you need to tweak a program or some task-generated code, let me show you how.

This example is taken from my latest book, Biostatistics by Example Using SAS Studio.

Editing the SAS Code Generated by the One-Way Frequencies Statistics Task

This is a good time to show you how to edit the SAS code produced by any of the SAS Studio tasks to customize a program. Click on the Code tab and the SAS program generated by the One-Way Frequencies request appears in the right-hand pane. It looks like this:

Figure 21: SAS Code Generated by the Request for One-Way Frequencies

proc freq data=SASHELP.HEART;
   tables Status Sex Chol_Status / nocum plots=(freqplot cumfreqplot);
run;

This program uses the FREQ (frequency) procedure to produce the frequency tables and plots for the One-Way Frequencies task. You provide a list of variables that you want to analyze on the TABLES statement. Following this list you see a forward slash. A general rule in SAS procedures is that statement options (TABLES is considered a statement) are placed following a forward slash. Thus, NOCUM and PLOTS= are options that affect how the tables and charts appear. As you probably guessed, NOCUM is the instruction to omit cumulative statistics from the frequency table. Two plots, one a simple frequency plot and the other a cumulative frequency plot are requested by the two plot request (FREQPLOT and CUMFREQPLOT).

Let's modify this program in two ways: First, you want to add a customized title to the output; second, you want to omit the cumulative frequency plot. Here's how to do it:

The first step is to click on the EDIT button at the top right of the code pane (see Figure 22 below).

Figure 22: Clicking on the EDIT Button to Edit the Program

one-way-frequencies-statistics-task

This action allows you to edit the task-produced program. To provide a customized title for the output, you use a TITLE statement. This consists of the keyword TITLE, followed by your title text, placed in single or double quotes. If any part of the title text contains a single quote, be sure to use double quotes to enclose the title.  Next, move the cursor to CUMFREQPLOT and delete it. The resulting program should now look like this:

Read More »

Post a Comment

SAS Jedi and DS2 Guru: Mark Jordan

SAS JediMaybe programming isn’t quite as dangerous as a lightsaber battle, but if you think using SAS to turn data into action feels a little bit like magic, you should know that nobody is better at harnessing “the Force” of DS2 than SAS Jedi Mark Jordan.

Mark has a resume that reads more like an adventurer than a software programmer. He grew up in Northeast Brazil, the son of Baptist missionaries, and served 20 years as a US Navy submariner. He has a twinkle in his eye and a spring in his step, and he’s practically a SAS wizard… well, a Jedi.

His SAS Press book Mastering the SAS® DS2 Procedure: Advanced Data Wrangling Techniques has gotten rave reviews at SAS conferences from users who wanted to take their SAS programming to the next level. Still not sure if DS2 is right for you? Check out this short video for Mark’s breakdown of the DS2 procedure, read some book reviews, and browse the free book excerpt!

 

Follow Mark on Twitter @SASJedi or visit his blog.

Post a Comment

How to turn your graphs up to 11

If you consider yourself as a visualization expert, you strive to create graphs that set you apart from the data analysts and statisticians. Graphs that merely plot the data in a clear/concise manner aren't enough for you. You want your graphs to also be intuitive, easy to read, and provide extra insight - graphs that go to 11! My friend Beth, who is into roller derby and therefore knows a thing or two about going to 11, helped me with this photo to get you into the right mindset for today's blog post ...

dial_11

 

Rick Wicklin recently wrote a post showing how to plot the ages of the presidents during their terms in office. It was a clear & concise graph that showed the start & end age of each president during their stay in the White House.

rick_president_graph

At the end of Rick's blog post, he asked "Do you think you can create a better graph that shows the ages of US presidents?" Can a graph guy turn down an invitation like that?!? ... Let's turn this graph up to 11!

I start by creating a simple graph very similar to Rick's, with only a few small changes. I only place a marker at the beginning of the arrow, so there isn't as much a problem with visual (and mouse-over text) overlap. I place the y-axis label 'Age' in the normal/horizontal orientation so it will be easier to read. I label the x-axis 'Year' instead of 'Inauguration Date' (since both the inauguration date *and* the end-of-term date are both being plotted along that axis). And since I'm not using two markers, I leave off the marker legend.

I think these change produce a nice clean graph, and a good starting point for my enhancements.

pres_plot

Rather than just the reference lines extending from the left axis, I added reference lines from both axes, so you can easily follow back from the markers to both the age and the year. And with reference lines from both directions, there wasn't really a need for axes or tick marks - therefore I got rid of them. I extend the y-axis down to 35 instead of just 40 (since 35 is the minimum possible age of a president). Now the markers & arrows stand out much more prominently than the reference lines and axes.

pres_plot1

Next I worked on the labeling. Rick used automated labels for all the presidents who were <=50 or >=65. The data points in this graph are a bit crowded, therefore if you use automated labels, you either have to allow collisions or allow the software to decide which labels to leave out or move. Either of those automated solutions can produce non-optimal labels, therefore I decided to annotate my labels manually, and selected exactly which labels I did (and didn't) want. I tried to label the presidents that were interesting and/or ones that had plenty of room for labels. Note that in the interactive html version of my output, I also have html mouse-over text for all the markers, so you can also see the names for the presidents that aren't labeled.

pres_plot2

At this point had a "pretty nice" graph ... but it still didn't quite "go to 11." Therefore I decided to make the 'area under the arrow' stand out a bit more, by drawing a triangular polygon there. I think having the visual area makes it a lot easier to visually compare the presidents. The triangular area also provides more area for the mouse-over text and drill downs, making the graph easier to interact with.(Click the image below, to see the interactive version with html mouse-over text.)

pres_plot3

Some people might ask - "what makes your graph better?" I guess I would have to answer "These go to 11."  :-)

 

Post a Comment

A graph for Trump - our oldest president

Recently, my fellow SAS blogger Rick Wicklin wrote a post showing how to graph the ages of all the US presidents. And Chris Hemedinger showed how to create a bar chart showing the number of presidents having each of the 12 zodiac signs. Both are interesting graphs, but I wanted to take a slightly different (more traditional) graphical look at the data - something more along the lines of a histogram. This would let me view the age distribution of all the presidents, and confirm whether or not Donald Trump is the oldest.

For me, creating a graph is an iterative process. I start simple, and then add little changes & enhancements (wash, rinse, repeat), until I have a visualization I'm happy with. Rather than just showing you the final graph, I'm going to walk you through my entire though process this time ...

I started with a simple Proc Gchart bar chart, using all the defaults. It produced a fine histogram, showing the number of presidents grouped by age, and I could see that 3 presidents were in the '70' age group. I knew Trump was 70, and I had heard he is going to be our oldest president ... but there appear to be two other presidents in the 'age 70' bar in this graph. I think I need to dig a little deeper...

pres_bar

I used the subgroup option, to create a separate colored bar segment for each president, to determine who the other two were. In theory, I could match the colors in the bars with the colors in the legend and determine who the other two presidents' names ... but it was really a chore to try and distinguish all those colors. To save you a bit of time, I've used a drawing package and circled the legend items that correspond to the colors in the '70' bar (Trump, Reagan, and Harrison).

pres_bar_subgroup

44 is a few too many colors for a legend - no, actually it's a ridiculous number of colors. Therefore I used a pattern statement to repeat a single color for all the bar segments. Then I used Gchart's 'html=' option to enable html mouse-over text. With that enhancement, I could hover my mouse over each bar segment and easily see not only the name of each president, but also their age at inauguration.

pres_bar_hovertext

With the mouse-over text, I found that the other two presidents in the '70' bar were both slightly less than 70. Gchart bars of numeric values show the midpoint of each bar in the label, by default. In order to show the range of values in each bar (min-to-max), you must specify the 'range' option. With that change, it was much more clear that the last bar didn't show the presidents who were 70 when they were inaugurated, but rather the ones who were >=68.

pres_bar_range

These automatically chosen ranges were nice and evenly-spaced, but they weren't really the ranges that I would have picked ... therefore I decided to go totally custom, and do my own binning. I used a data step and 'if' statements to check each president's age, and assign them to 7 bins, representing age ranges that start and end on even multiples of 5. I then created a user-defined-format so that those ranges (1-7) would show up as the text representation of the ranges (such as '>=70'). The resulting graph clearly showed that Trump was the only president >=70!

pres_bar_custom_range

Now that I had the layout the way I wanted, I shifted my focus to the cosmetic details. I made the bars a prettier shade of blue, cleaned up the axes, added some reference lines, and annotated the presidents' names on each bar segment (here's the final code). The results might not be perfect, but it's what I would call a blue-ribbon graph! Click the image below to see the interactive version, with html mouse-over text and drill-downs.

pres_ba5

Quick quiz:

Which last names are repeated multiple times in the graph?

What's the youngest and oldest ages allowed to run for president in the US?

 

Post a Comment

Send your SAS graphs to Excel, directly to Excel ...

Are you the lone-wolf SAS programmer in your company - managing the data, performing the analyses, and graphing the output for everyone else? And what's the only format they all know how to work with, and wish they had your output in? Let's face it ... that's probably an Excel spreadsheet!

Previously you had to jump through some hoops to send SAS graphs to an Excel spreadsheet, but now you're in luck! In SAS 9.4 (TS1M3), there's an easy new way to send your output (including graphs) to Excel. Directly to Excel! (Do not pass go, do not collect $200!)

go_to_excel

Chris Hemedinger gave you a little preview of the experimental version of ODS Excel in SAS 9.4M1 and 9.4M2. And we now have the production version in 9.4M3! An astute user (Frank Tokic) actually brought this new feature to my attention, and provided an example of using it with SAS/Graph (thanks Frank!) I modified Frank's example to also demonstrate a few additional features, and I think it makes a great starting place for anyone interested in sending SAS output to Excel.

The example demonstrates:

  • Sending a traditional SAS/Graph Gchart to an Excel spreadsheet.
  • Sending a SAS Proc Print table to an Excel spreadsheet.
  • Starting the table at a specific row & column.
  • Including the title text above the table.
  • Using date-formatted data in the table.
  • Writing the graph and table to separate sheets.
  • And controlling the names of the sheets.

Here are screen-captures showing the graph and table in the spreadsheet:

excel_sas_graph_cap

 

excel_sas_table_cap

 

I'm including the SAS code below, and also including links to the code and xlsx output files.

data my_data;
input item $ 1-6 Amount Purchase_date date9.;
datalines;
ITEM A 11.8 14nov2016
ITEM B 10.5 01jul2016
ITEM C 8.8 22feb2015
ITEM D 6.8 01apr2012
ITEM E 3.9 03aug2016
ITEM F 2.3 02mar2016
;
run;
 
ods listing close;
ods excel file="excel_sas_graph.xlsx" style=htmlblue;
 
goptions gunit=pct htitle=6 ftitle="albany amt/bold"
htext=3.5 ftext="albany amt/bold" ctext=gray33;
 
axis1 label=none value=(justify=right);
axis2 label=('AMOUNT') order=(0 to 12 by 2) minor=none offset=(0,0);
 
pattern v=solid color=dodgerblue;
 
ods excel options(SHEET_NAME='Graph');
 
title1 ls=1.5 "Simple Bar Chart";
proc gchart data=my_data;
format amount dollar5.0;
hbar item / discrete type=sum sumvar=amount nostats
maxis=axis1 raxis=axis2 noframe
autoref clipref cref=graycc;
run;
 
ods excel options(SHEET_NAME='Data' EMBEDDED_TITLES='yes' START_AT='3,2');
 
title c=gray33 "Raw Data Values";
proc print data=my_data noobs label;
label purchase_date='Purchase date';
format amount dollar5.2;
format purchase_date date9.;
run;
 
quit;
ods excel close;

Hopefully this example will get you started with the basics. ODS Excel is pretty new, and therefore I'm not an expert (yet), but hopefully the documentation will answer most of your questions. And if that doesn't satisfy all your curiosity, I'd recommend posting your question in the SAS community pages.

 

 

 

Post a Comment

Where did all my daylight go?

Does it seem like there just aren't enough daylight hours to get things done these days? It might not be that you've got more to do - it might be that we actually have fewer daylight hours in the winter (here in the northern hemisphere). And since "seeing is believing," let's graph the data to see what's actually going on!

First, I looked around and found a website where I could get the sunrise & sunset times for various cities, and generated a URL to get the data for Raleigh, NC. Here's what the text data looks like:

time_data

Next I wrote some SAS code to read the data (directly from the website, by the way!), and manipulate it into a form that I could easily use to create my graph - for example, rather than having a separate variable/column for each month, I wanted all the dates to be values of a single variable. What I wanted to do was sort of like transposing the data, but rather than using Proc Transpose, I used a data step with multiple output statements for each line of data.

Once I had my data ready, I was able to create a simple stacked bar chart with a separate (very narrow) bar for each day of the year, showing the hours before sunrise, the daylight hours, and the hours after sunset. It's not a pretty graph (yet), but it showed me that I was on the right track:

daylight1

Now, let's make the graph pretty... I started by cleaning up the axes. Bar charts typically label each bar, but in this case 365 bar labels showing the date just won't fit. So I use an axis statement to suppress those bar value labels (using the value=none option). The left/time axis auto-scaled and picked reasonable times to show along the axis, but I thought something a little simpler might be better. Therefore I used the order= option to specify which tick marks I wanted, and I used the value= option to specify some custom text for those tick marks (for example, '6 am' rather than '6:00:00 AM'). This graph is cleaning-up nicely, eh!

daylight2

By default, each bar has an outline drawn around it. Outlines are usually desirable, but with 365 tiny bars the dark outlines are a bit overpowering - therefore I get rid of them using the coutline=same option. Also, rather than using the default colors (blue, red, and green) I specify colors that will be more intuitive and meaningful (black and yellow). Now, the time periods before sunrise and after sunset will be dark, and the daylight hours will be yellow (sunshine-colored). This graph is really starting to look a lot nicer - you can clearly see that the summer months have more daylight hours than the winter months!

daylight3

And for a few finishing touches, I annotated some custom month labels along the bottom of the graph, added some dotted reference lines, and placed a title at the top to describe what's in the graph. I think this is a fine representation of the data, and much easier to understand than the text table!

hours_of_daylight

But when analyzing data, sometimes "the devil is in the details" ... Did you notice the footnote at the bottom of the text data file (I've circled it in red below)? This means we're not quite finished. We need to figure out how to represent the time shift of daylight savings time in the graph!

dst_note

Here in the Eastern time zone of the US, we use daylight savings time (dst). This is where we all turn our clocks forward an hour in the summer months, to trick everyone into waking up an hour earlier and take advantage of the earlier sunrise. In order to represent that in the graph, I did a Web search and found the dates that dst started & stopped in 2016, and added a 1-hour offset to the sunrise and sunset times for all the days between those dates. The following graph shows what we actually experience, with the artificial dst shift.

hours_of_daylight1

I hope you had fun and maybe even learned a little something!

Now for a side-question ... what's your opinion on daylight savings time? Do you like it or dislike it? Did you prefer the old dst we used to have, or the new dst we've had since 2007 (where they added a few extra weeks)?

And what better way to end a blog about sunrise/sunset, than a picture of someone waving goodbye in a beautiful sunset in Naples, Florida. (This picture is from my friend Eva, and this is her man Todd waving.)

eva_naples_sunset

 

Post a Comment