How to show recessions (or other ranges) on a time series plot

It's easy to plot events that happened at a certain time, but what about events that extended over a range of dates, such as recessions? ... This blog post teaches you a nice trick to use for that!

Let's say you have a plot of the labor force participation rate over time, and you want to also see when the recessions started and ended. Here's the way I would plot it:

labor_participation

How do you do that in SAS? If you've seen any of my previous blogs, you probably know that the trick I use to add things to graphs is almost always annotate. Annotate gives you a way to programmatically 'draw' extra things on a graph. And in this case, I use it to draw a colored box behind the graph, extending in the left/right direction from the start date to the end date of each recession, and extending in the up/down direction from the bottom of the axis to the top.

Here's a short example that shows how to code it. Notice that I use the data coordinate system for the x direction (xsys='2') so I can specify the dates, and I use a %-based coordinate system for the y direction (ysys='1') so I can simply specify the values 0 and 100%. The when='b' draws the solid-colored bar before (ie, behind) so it doesn't obscure the plot lines.

data anno_recessions;
xsys='2'; ysys='1'; when='b';
x='15apr1960'd; y=0; function='move'; output;
x='15feb1961'd; y=100; function='bar'; color='cxf0f1e6'; style='solid'; output;
run;

What about events other than recessions? - Certainly! It could be any event with a start date and end date. And if it's not obvious what the event is, just stick a label on it!

homes

Or what about which president was in office? Yep - you can use the same trick to show that!

voters

What about "graying out" a special region of a Salmonella chart? Sure! With a slight modification, you can use an alpha-transparent gray color, and annotate it after the graph (when='a' so it is drawn on top).

salmonella_epi_curve

What about showing a season of the year, such as 'winter'? ... You betcha!

snowfall_barchart

You can even use this technique to simply alternate a background color (like the old green bar paper) instead of using reference lines.

dow_unblinged1

 

I've set up each of the graphs above so you can click on them to see the 'info' page which has a link to the SAS code used to create the graph. Feel free to download the code, and modify it to work with your data.

Now it's your turn - do you have any tricks that you'd like to share for enhancing time series plots? If so, leave a comment below!

Post a Comment

Mapping 206 hospitals in 29 states!

If you're a really big company, with many locations around the country, how do you keep track of all that? ... With a great map, of course!

I recently read a CNN article about the Community Health Systems network being hacked - exposing the names, Social Security numbers, physical addresses, birthdays and telephone numbers of 4.5 million patients. That's mind boggling, isn't it?!?

I'm always looking for different ways to use SAS, and I thought maybe we could use it to plot the locations of their 206 hospitals on a map, so people could easily see if their hospital is one of those impacted by the hackers.

The article included a map, but it was small and didn't really provide enough detail to be very useful. My new/improved SAS version is below - you can click it to see the full size map, and it will let you hover your mouse over each marker to see the hospital name. I also included the full text list of all the hospitals (below the map), in case you want to search by city name, etc.

community_health_systems

That's a nice looking SAS map, eh?!? You're probably wondering "How'd he do that?!?" ...

Well, I started with a list of all the hospitals, and the city & state where each was located. I used Proc Geocode to find the latitude & longitude of the cities, and then plotted a marker at each of those locations using annotate. I used Proc SQL to count the number of hospitals and states, and saved the results into macro variables which I also annotated on the map. ODS HTML allowed me embed html tags so that each marker has hover-text with the name of the hospitals. And, most importantly, it's all data driven (no hard-coding of marker locations or numbers) - therefore to change what I'm plotting on the map, all I have to do is change the data!

Have you got some data that you might want to plot on a map like this? Here's a link to the SAS code, in case you want to try your hand at re-using it. Feel free to leave a comment about this map, or a map you might create with your own data!

 

Post a Comment

What's trending in your neck of the woods?

"Trending" is one of those words that's trending these days, as we verbify everything. And if you understood that, then you'll probably love this blog! :-)

For those of you not hip to the lingo ('hip' meaning 'knowing about and following the newest styles, fashions, etc.'), dictionary.com defines trending as "to emerge as a popular trend; be currently popular."

I recently ran across an article describing a new map that shows which YouTube videos are trending in various parts of the US. The map interface allows you to select things like gender and age, to see what videos are most popular (or trending) with that demographic. It's really cool - give it a try! ... but please come back to read the rest of the blog, so you can learn how to create such maps in SAS!

youtube_trending_map

 Like I do with most cool maps & graphs, I decided to come up with a way to create a similar map using SAS! I don't have access to the YouTube viewership data, so I took the liberty of creating some 'plausibly real' data showing what SAS-related YouTube videos are trending in various cities. And whereas the original map appears to use pre-determined cities (arranged in neat rows and columns by hand), I will set mine up so the city locations are data-driven.

I used Proc Geocode to determine the latitude and longitude of each city (note that if you had IP addresses of the viewers rather than city, Proc Geocode can also be used on IP addresses!) I then created an annotate dataset encoding commands to move to each lat/long coordinate, and then switch to a relative-percent coordinate system and then move a certain percentage down and to the left of the center coordinate, and then draw an image icon that extends the same percentage distance up and to the right of the center coordinate. Here's a link to the actual code.

And here's my SAS version of the map! Note that the data is fabricated (not real), but the videos that the icons link to are real.

trending_videos_map

Now that you know how to create such a map in SAS, what data might you have that would be interesting to plot in this way, with little image/icons? Share your ideas in the comments section!

 

Post a Comment

If US state borders were redrawn -- which new state would you live in?

Find out which state you'll live in, if the US state borders are redrawn so we have 50 states with equal population! (Don't worry! - This is just a fun/hypothetical "what if" blog!)

To get you in the mood for this topic, here's a picture of one of the many vintage globes my good friend (and antique dealer) Reggie has in his personal collection. I always like looking at old globes to see if I can find borders & country names that have changed, and then try to guess the age of the globe based on that information. ... Which brings us to the topic at hand - changing the borders and names of the 50 US states!

globe

For those of you not familiar with the US, it is divided into 50 states (represented by the 50 stars on our flag), and the population of some states is huge (such as California, with 38 million people), while the population of other states is small (such as Wyoming, with 600,000 people). This population disparity makes it a bit awkward when trying to determine how much influence each state has in the US government, etc.

I recently saw a map Neil Freeman created, that proposed dividing the US into 50 new states with an equal population in each area. Being a "map guy" myself, this caught my attention. I read the details in his article, and I liked the factors that he had used in coming up with the new groupings - "The map began with an algorithm that grouped counties based on proximity, urban area, and commuting patterns. The algorithm was seeded with the fifty largest cities. After that, manual changes took into account compact shapes, equal populations, metro areas divided by state lines, and drainage basins."

redraw_50_states

But, in scrutinizing his map, I found that I couldn't easily determine which of the current states & counties were included in the new proposed states. Therefore I created my own version of the map with SAS, which could easily answer those questions!

In my SAS version, I use the counties as my basic building blocks, and I add html hover-text so you can hover over any county and see the current state & county, and the proposed new state name. I also annotate the state borders (in white) so you can easily see how the current state borders compare to the new state borders. Therefore, while Neil's map makes a better static poster (which was his goal, by the way), the SAS map provides more analytic capabilities and insight. ... And having both maps gives you the best of both worlds!

Here is my SAS map. Click the static thumbnail below, to see the full-size interactive map with html hover-text.

us_equal_population_map

If this change were to happen, what new state would your current residence be in, and what new state would you prefer to live in (and why)?

Post a Comment

Your SAS Visual Analytics expert is here

Ask the expertWouldn’t it be nice to have an expert to answer your SAS Visual Analytics question?

Now you do and the best part, it’s free!

Beginning September 8, SAS will be hosting a one-hour Ask the Expert session each Monday through November. Each interactive session will focus on a specific Visual Analytics topic area as indicated below:

SAS VA schedule

After each session, a session recap will be posted to the SAS Visual Analytics Community. The session recap will include a link to the session recording as well as a list of question and answers. For each question we will include links to additional details and more information. Make sure to check out the session recap whether you can attend the live session or not.

Please start gathering your questions and plan to attend one or all twelve sessions. Use this link to register for each session that you would like to attend.

We look forward to answering your questions and helping you to get the most out of SAS Visual Analytics!

Post a Comment

Not the same ol’ middle tier

The SAS Middle Tier is all new for SAS 9.4, and you might not recognize it. Gone are the third-party web application servers. Gone is the third-party Java development kit. Missing major components like those may cause you to ask yourself, “Does SAS still have a middle tier?”  With the introduction of the all new SAS Environment Manager the answer is an emphatic, “YES!” The third-party products are not needed because every component is 100 percent SAS homegrown.

The new SAS Middle Tier Architecture looks like this:

middle_tier_1

No need to worry. We understand that even though you see some familiar applications, much of this diagram is likely new to you. To help you navigate the new SAS 9.4 Middle Tier we introduce to you the new SAS Platform Administration: Middle Tier Administration course.

A highlight of the course is the SAS Environment Manager, a web-based administration tool for the SAS environment. The following screen shot shows how the SAS Environment Manager displays the status of your entire environment in one dashboard:

middle_tier_2

middle_tier_3

The availability column is refreshed every minute indicating the health of the resource in question.

While more functionality will be added to the SAS Environment Manager over the SAS 9.4 lifecycle, it is not yet a replacement for its older brother, SAS Management Console. SAS Management Console still rules when it comes to managing metadata access.

You can learn more by checking out the SAS 9.4 Intelligence Platform: Middle-Tier Administration Guide. Or view the administration curriculum path to see what else is offered.

Post a Comment

Tracking Ebola: Layering customized SAS maps

There are many ways to use SAS in Health & Life Sciences, and one of my favorite is using it to track the spread of diseases. This post demonstrates how to layer several customized maps to track the recent Ebola outbreak in Africa.

For those of you who are impatient and want to "cut to the chase" here's my final map. It is a SAS version of a map that appeared in a recent article on the bigmedicine.ca website. Click the thumbnail below to see the full size interactive version of my map with html hover-text.

ebola_africa_2014

 

And here are the technical details of how I created this map...

I used the new mapsgfk maps that we started shipping in SAS 9.4 for this example. I started with the mapsgfk.Africa continent map, and used Proc Gproject to chop out just the rectangular area, based on latitude/longitude values, that was in the original article. (This is a technique I learned from Mike Zdeb's wonderful book Maps Made Easy using SAS.)

proc gproject data=mapsgfk.africa out=my_map latlong eastlong degrees 
 project=cylindri
 latmax=14.0 latmin=0
 longmin=-20 longmax=-3.2;
id id;
run;

I created some 'map data' so that the affected countries mapped to the light yellow color, and left the other countries gray (using 'cdefault=grayE1').

ebola_africa_2014_countries

 That was the easy/straightforward part :) Now I need to add the individual country maps for Guinea and Liberia. I was able to use mapsgfk.Guinea as-is, but mapsgfk.Liberia's areas were 1 level more granular than I needed (such as US counties, instead of states), therefore I had to use Proc Gremove to group those lower-level areas into the desired areas. Once I had created these two maps, I combined them with the previous map, layering them such that these two new maps come last in the dataset, so they will show up 'on top'.

ebola_africa_2014_areas

We've now got a map with the countries and areas together, but it's difficult to determine exactly which country the smaller areas are a part of. Therefore I take the country borders, and create an annotate dataset to draw a dark outline around each country using the poly/polycont annotate commands. This is an improvement over the original map, by the way!

ebola_africa_2014_outlines

And to finish it off, I annotate country & city names at specific latitude/longitude coordinates, and annotate a blue rectangle behind the map to represent the ocean. I annotate the 'Capitals' marker to the legend, and add the date to the bottom/right. I add html hover-text to all the countries and areas within the countries, using the Gmap html= option, so you can mouse over them and see what the names are (which is another enhancement over the original map). Scroll back to the top of the blog to see the finished map.

As you can see, you can do a lot of customizations in SAS maps, and you can layer maps (and also annotations) to create some really detailed maps to help visualize and analyze your data. Now that you know what's possible, what data do you think it would be interesting to analyze on a map?

 

Post a Comment

A tale of two administrators

You are the new SAS Administrator. After the initial shock or excitement, you sit back and wonder, “What does that MEAN???” In an enterprise environment there are often divisions of duties. The SAS Intelligence Platform is no exception. Just take a look at the architecture.

SAS Intelligence Platform

Just looking at this picture, you can probably tell there are potential turf wars here. As the SAS Administrator you may have to interact with database administrators, server or system administrators, middle tier administrators and even desktop support. In other words, the SAS Administrator will have to know enough to be dangerous about various aspects of the environment. Our SAS Platform Administration: Fast Track course is designed to cover the entire platform in a short amount of time.

But what if you are not the administrator of the entire domain? How do you understand the platform for SAS Business Analytics without drinking from the fire hose that is the SAS Platform Administration: Fast Track? The answer is: It depends. It depends on what type of administrator you are. The good thing about SAS is that it is flexible and configurable, but in the wrong hands, what is good can be bad. So let’s get you started in becoming the best SAS Platform Administrator you can be.

I have to begin by asking you some questions.

  • Do you administer the SAS Platform for Business Analytics, but you do not have administrator rights to the server?
  • Do you use SAS Management Console and support SAS applications, but you rely on someone else for your operating system administration?

If your answer to these questions is, ‘Yes, that sounds like me!’, then the new SAS Platform Administration: Metadata Administration course if for you! You would be what we call a SAS Metadata Administrator. Your focus is on metadata security, adding users, and business intelligence content, such as SAS Stored Processes or SAS Reports. This course teaches you the terminology and skills to manage the platform for SAS Business Analytics through use of SAS Management Console.

If the last paragraph bored you to tears and you have no desire to manage metadata, BUT you do manage server machines and the processes that run on them, you are not left in the dark. You are the type of administrator we call a SAS System Administrator. To you, your concern for SAS is from the operating system perspective. The course you should take is SAS Platform Administration: System Administration 9.4. With the knowledge gained in this course you will be able to:

  • administer and back up the SAS configuration and metadata
  • administer, monitor, log and troubleshoot the SAS Metadata Server and other SAS processing servers
  • utilize the SAS Environment Manager.

The courses are independent of each other, so you take the course relevant to the type of SAS Administrator you are. If you need both, the fact that they are independent from each other helps because you can take them in any order. Now that you know the type of SAS Administrator you are, we look forward to seeing you in class soon!

If you are completely new to the SAS platform, you may want to take the Getting Started with the platform for SAS Business Analytics course which provides an overview of the platform and the various client applications that it supports. The course is valid regardless of which platform administration course(s) you take.

You can view all of the platform administration courses on the administration curriculum path.

Post a Comment

Oh buoy! It's time for some Shark Week graphs!

With Discovery Channel's Shark Week starting on August 10, I decided to sink my teeth into some shark-attack data - I even found there were some shark attacks in the Midwestern US! Read on to learn the details...

To get you into the shark mindset, here is a photo of an almost 7-inch fossilized tooth from a prehistoric megalodon shark. My friend Rochelle found it while diving off the North Carolina coast. This is about as big as they get, and would have belonged to a shark that was over 50 feet long!

meg_tooth

Most people have a morbid curiosity when it comes to sharks attacking humans (especially after the movie Jaws). So I did a bit of searching, and found the sharkattackfile.net website that maintains an impressive list of shark attacks ... but I noticed they didn't have a very good interface to help explore and analyze the data. Therefore I downloaded their data, imported it into SAS, and set up a little proof-of-concept showing how SAS can provide a visual interface to help you quickly 'see' more about the data.

Click the map snapshot below to see the full-size interactive version, where the states have hover-text, and drill down to a table listing all the shark attacks in each state. The table then has links to the detailed pages for each individual shark attack.

shark_attacks

Looking at the data plotted on a map, the first thing that jumps out at me is that several of the inland states in the middle of the US have had shark attacks! How in the world does that happen?!? I clicked those states to see the individual incidents in the table, and then clicked the link in the table to see the details. Sure enough, humans had been 'attacked' by sharks in those states! I'll let you investigate (as I did above) to find out what those details are :)

The map is color-coded by gradient shades of (blood) red. You can tell that Florida has the most shark attacks (probably due to having more shoreline and more days warm enough to go to the beach, etc), but it's difficult to tell exactly how the values vary from state to state. Therefore I also created a bar chart of the same data. Looks like North Carolina is in the "top 5" - yikes!

shark_attacks1

So tell us your "shark story"! Did you see the Jaws movie when it first came out? Have you ever had a close encounter with a shark? Feel free to leave a comment and tell us your shark tale! (... or is that 'shark tail'?)  ;-)

 

 

Post a Comment

Thanks a Million

In July, we trained our 1 millionth user. It’s a significant milestone for SAS.

In celebration, we want to recognize our customers and say “thank you” for making a commitment to us for your learning.

Now through Aug. 31, we are offering a special Buy One, Get One 50-percent off promotion for public classroom or Live Web courses.

To receive the discount, you must register for both courses by Aug. 31. You can choose from any of the hundreds of courses we offer between now and the end of the year.

When registering online, include both courses in the same shopping cart and type MILLION into the promo box for both courses. The 50-percent discount will be applied to the lower-priced course.

You may also register and receive the discount by phone at 1-800-333-7660. Just mention the promotion when registering.

Visit our special “Thanks a million!” web page for all of the details and instructions on the promotion.

It’s a rewarding time for us here at SAS Training, and we take great pride in the fact that our customers consistently rank our training as excellent. But we’re not resting on our laurels. We remain committed to helping you learn SAS by offering a number of programs and services designed to get you the training you need, when you need it.

Thank you again for continuing your SAS education with us. We hope to train a million more.

Post a Comment