We’re smarter together. Learn from this collection of community knowledge and add your expertise.

How to get started with SAS University Edition - Part 6

by Regular Contributor on ‎02-21-2015 11:51 AM - edited on ‎10-05-2015 03:09 PM by Community Manager (1,648 Views)

This is it – the final post in my series on SAS University Edition.  This post is for all users, but I would guess that those who are intermediate in their comfort level (for example those who can do some programming, but acknowledge the fact that there is still quite a bit they don’t know, or who have using SAS 3 – 5 times a week for 2 or 3 years) would get the most benefit.  This article is covering something similar to the Tasks that were covered previously, but in some ways is much cooler – they’re called Snippets.


Double clicking on the Snippets menu item on the left side of the screen pulls a menu that looks like this:



When you double click on the Data menu, you will see a number of choices.  I’ll go through a sample of them briefly.  Double clicking on the first item in the Data menu, you will see a piece of code that is displayed in the Code window.  From the comments, you’ll see that this is the IMPORT CSV FILE snippet, and allows you to “fill in the blanks” in the code to import your data.  It also provides PROC PRINT to ensure that the data was imported correctly.




The next snippet is the IMPORT XLS FILE, and like the CSV file, allows you to provide the location of the dataset and it’s ready to go.



Next on the list are three DS2 snippets (DS2 PACKAGE, DS2 CODE and DS2 THREAD). I admit I know nothing about DS2 language, so I’m going to skip these and stay with the ones I’m comfortable with.


The next one then is the GENERATE CSV FILE, but rather than just saving the new file somewhere, the snippet sends the CSV data to your default browser, something I a) didn’t know I could do and b) really like.




This next snippet is one that I personally am the most excited about – sending your SAS output directly to Powerpoint.  How many times have you created a large number of tables and graphs only to miss one when copying/pasting them to your presentation? With this snippet as an example, that will no longer be an issue!




On my Mac, I’m prompted whether I want to open or save the new file.  I opt for Open by clicking OK.




Here’s my output, presentation-ready!




SAS also generates the same output in the Results tab; I use this feature to validate the output, ensuring that the titles etc. are the same.




Next on the list is GENERATE XML FILE; in the age of ever-increasing data transmission requirements, having an easy way to create an XML document right from SAS makes the uploading of data that much easier – all with 8 lines of SAS code!




Here is a small sample of the CARS.XML file that is automatically opened in my browser. Not the most user friendly of formats, but that’s not XML’s purpose.




Moving on to the next section, the Descriptive snippets, the first is CUSTOM ODS OUTPUT.   Ridiculously easy, but for a user that’s never exported to a PDF or RTF, using this snippet makes a world of difference.



For anyone that I have not had the chance to meet (either online or in person), I have a confession to make – I’m a PROC SQL junkie.  I’ve been using SQL for over 15 years, and when I was reviewing different stats packages, I chose SAS because it had SQL as a fully functional PROC. I then used PROC SQL as a “gateway PROC” to the full power of SAS.  However, for a user that’s never seen SQL, having this snippet allows them to see that it is very simple and “plain English” syntax.  I’m not sure why SAS used PROC PRINT rather than a SELECT to output the data, but on the plus side this once again shows the versatility and flexibility within SAS.



The next section of snippets are the Graphs, and the first one I’ll cover is the BAR PANEL.  I’m going to focus on graphs not covered in the TASKS post, just to keep things interesting.  Using SGPANEL, the snippet shown below uses the CARS dataset and outputs the bar panel to the Results tab.




The bar panel is shown below, with the title, axes, and panels labeled appropriately.



The second example is the Box Panel, this time using the HEART dataset and breaking the population down into “Normal” and “Overweight” for the panels.




As with the Bar Panel, the titles and labels are all applied by SAS and this graph, for all intents and purposes, is ready for your presentation or publication (or, as more often the case, further analysis!).




I’ve mentioned this a couple of times over the span of my posts, but there are certain graphs that I feel are habitually over used (histograms) and others that are under utilized; COMPARATIVE SCATTER PLOTS are, in my experience, definitely in the latter.




Below is the output, nicely broken out into an easy to read matrix, clearly highlighting outliers and clusters.




The next graph is a very basic example of the power that these snippets (and SAS University Edition in general) provides.  The FIT PLOT allows the user to take their data and plot, as in the screen shot, a CL Mean with a regression line.  As powerful as the other examples have been, this is where SAS truly shines.




Below is the screen shot of the plot for cars made in the USA, with the CL mean and regression line.  I’m not sure if the jittering of the dots is an automatically done in the PROC SGPLOT for this type of graph, but I am happy that it is done here as it makes the data easier to view.




Although mainly used in the finance industry, I do see application for the HighLow plot in other areas (healthcare, for instance).  Having the snippet allows me to quickly see what the code is necessary to generate such a graph, which I can then modify to my own needs.



As the screen shot below shows, having this sort of graph quickly shows the variation within the time series data.  Having it done as quickly as clicking on the snippet and pressing Run makes it even more accessible to users of SAS.




The SCATTERPLOT MATRIX, similar to the Comparative Scatter Plot described above, allows for multiple variables to be put side by side allowing for easy visual analysis.




Here’s the output; as you can see, the variables are down the diagonal, with the axes labels on the outside.  The first plot on the top row is therefore Highway x City, and the first plot on the second row is City x Highway.  This can be confusing for new users of a comparative scatter plot, but I find it easier when I remember I only have to look above or below the diagonal – otherwise the graphs repeat themselves.




The last graph I’ll be talking about is the VBOX PLOT, again using the CARS dataset. Reviewing the code does not reveal anything out of the ordinary, but may seem a bit intimidating to users that are unfamiliar with the PROC SGPLOT options.  I highly recommend reading the SAS documentation and any one of the numerous books on the topic of graphs in SAS.




Here is the vertical box plot, highlighting sedans versus sports cars made in Asia, Europe and the USA.




The second last section covers the IML snippets.  I must admit, IML intimidates me – but I’m also not a mathematician or statistician.  I have a couple of Rick Wicklin’s books on my shelf, and I peruse them from time to time, fully anticipating that osmosis will kick in and I’ll understand what he’s writing.  Having said that, having these snippets available means I can go in and play around with code that is from Rick’s books; I can see in real time how changing values, removing options etc. will impact the output.


Here’s the list of IML snippets available:



The first one I’m going to highlight is FIND ROOTS OF A NONLINEAR EQUATION.  As you can see from the comments in the code, this is taken directly from one of Rick’s blog posts, and the URL is provided as a reference.




Here is the output from the above code, with the roots provided in a table below.




The second snippet I want to cover is the GENERATE A BOOTSTRAP DISTRIBUTION.  I have never had the need to use (or rather, I’ve never had the need to think I need to use) a bootstrap, but the amount of comments provided in this piece of code helps me at least understand the basics, and with the reference in the top comment, I know there are other resources available.



The last bit I wanted to cover is not a snippet, but a feature that is very handy. It’s “Add to My Snippets”, so if you have code that you use over and over again, clicking the  Snippets_30B_insert_in_text.png button will allow you to do this.  The window below will open, and all you need to do is provide a name.


Clicking Save means that it is now available in the My Snippets menu, ready to use whenever it’s needed!




As this is the last of my posts in this series on SAS University Edition, I wanted to take a couple of seconds and thank some people who were extremely supportive of me undertaking this.  Matt Malczewski from SAS Canada for originally giving me the idea to work with SAS on this; Christina Harvey for originally willing to work with me on this; Chris Hemedinger, Lainie Hoverstad, Amy Peters and any one else that read the first of the series for their reviews and, most importantly to Bev Brown for her patience, comments, and taking the time to walk me through the posting process. I hope that this is the first of many articles I’ll be posting here, and I look forward to your feedback!




This is article #6 in a six-part series. Links to all of them are below:



by Super User
on ‎03-04-2015 11:25 AM

TERMSTR for Unix is LF not CR.

by Regular Contributor
on ‎03-04-2015 11:53 AM

That screen shot is of the automated code generated by SAS University Edition so would be a bug in scripting; guess that's one for Support :smileylaugh:

Thanks for reading, and glad the mistake you found wasn't mine! haha


by Community Manager
on ‎03-05-2015 04:31 PM

We're on it, thanks!

Your turn
Sign In!

Want to write an article? Sign in with your profile.