Confessions of a SAS Dummy

SAS Global Forum 2014 was a ton of fun, and extremely busy for yours truly. If you wonder how I spent my time at the conference, you need only to visit the on-demand video archive and see how many of the various sessions feature my shiny head.

In most of these videos I'm a bit player, acting only as a host while some smarter people share the interesting demos and insights. But I do have one video that's all my own. And it features content that I "test marketed" on this very blog. The session is called "Confessions of a SAS Dummy".

Description from the conference schedule:

People from all over the world are using SAS analytics to achieve great things, such as to develop life-saving medicines, detect and prevent financial fraud, and ensure the survival of endangered species. Chris Hemedinger is not one of those people. Instead, Chris has used SAS to optimize his baby name selections, evaluate his movie rental behavior, and analyze his Facebook friends. Join Chris as he reviews some of his personal triumphs over the little problems in life, and learn how these exercises can help to hone your skills for when it really matters.

This presentation is a reprise of talk that I've given at several user groups, including as a keynote feature in two regional SAS user group conferences last fall. Now, since it's recorded and viewable by anyone at any time, I can probably never give it again. I guess I'll have to find some other topics to milk for my in-person appearances.

I've had friends who watched the video (and I didn't even have to pay them!) and said (with a hint of pity), "I enjoyed the talk, but the audience didn't seem to be all that entertained." Well, I was there and I can tell you that my audience was very good, and I was pleased with their feedback. Unfortunately, unlike at the taping of a sitcom episode, the audience is not miked so you can't hear their reaction as I speak. You can hear their questions at the end only because the questioners use a microphone for that part of the session.

Perhaps I'll petition the video editing team add a laugh track. If you're feeling charitable, feel free to leave some chuckles in the blog comments.

Archived recording: [VIDEO] Confessions of a SAS Dummy

Post a Comment

Talking Tech at SAS Global Forum 2014

Talking tech with Nancy R. at SASGF13

For the third year now, I'll be hosting the SAS Tech Talk shows at SAS Global Forum. (Since I've been invited back I can assume that I'm more of an Ellen DeGeneres than a Seth MacFarlane.)

These shows feature SAS technical experts (mostly from SAS R&D) who are prepared to discuss and demonstrate the technologies that they work on. These folks have job titles such as "Chief Data Scientist", "Principal Research Statistician", and "Senior Analytical Consultant". They work in areas such as "SAS Output Delivery and Reporting", "BI Data Visualization", and "Enterprise Management Integration".

These guests represent the SAS R&D talent that bring the SAS products to life. Some will be names that you know from books and blogs, such as Rick Wicklin. Others are return guests to SAS Tech Talk, such as Nascif and Himesh. And still others might be faces that are new to you, but they are the movers and shakers when it comes to SAS technology.

This year we have three SAS Tech Talk shows:

  • Monday, 24March at 2pm EDT
  • Tuesday, 25March at 2pm EDT
  • Wednesday, 26March at 9am EDT

Each show is different, and we're covering 12 great topics in all. I'm very excited about this year's lineup! I'd list out the topics right here, but some are the subject of exciting product announcements and I don't want to steal anyone's thunder!

There is no doubt that you get the best conference experience when you can attend in person. But even if you cannot attend this year, you don't have to miss out. Much of the content -- the opening sessions, SAS Tech Talk, and many breakout sessions -- will be streamed on live video channels, all hosted at www.sasglobalforum.com. Any content that is streamed will also be archived so that you can watch it later (can you say "movie night"?).

See also
Previous SAS Tech Talk shows on YouTube

Post a Comment

Adding some culture to your SAS Enterprise Guide prompts

My teenage daughter is a self-appointed anglophile. She's a big fan of British movies and TV shows such as Doctor Who and Sherlock, and although she has not yet visited the UK (an injustice for which she blames her father), she considers the place to be her homeland.

In an effort to live out her adopted British lifestyle, she changes her iPhone and laptop settings to "English - British". It's an innocuous preference, usually. However, it does occasionally create a problem, such as when she accidentally turns in schoolwork with British spellings for words such as "honour" or "colour". (As the famous quote from George Bernard Shaw points out, we are two nations divided by a common language.) Fortunately, her teachers sympathize (or "sympathise") and don't usually deduct points for these "misspellings".

SAS Enterprise Guide (and other SAS applications) are translated into many languages, but for these apps "English is English", and there is no special affordance for those users in the UK or Australia. For these users, running SAS Enterprise Guide in English means running it as "English - United States". Even though the language is the same, there are a few local customs, such as the format of date values, that can confuse end users.

These differences are evident in a few places, including in the prompt dialog for date values. When running in "English - United States" mode, a "Date"-type prompt looks like this:

The display value is USA-style, but more confusing is what happens when you try to enter a date value. Even though the prompt window displays the current value with the full month name, the user can enter date values by using a variety of different value styles. In the USA, we usually enter dates as "MM/DD/YYYY", where "02/10/2014" is interpreted at February 10, 2014. But a British or Australian user, accustomed to "DD-MM-YYYY" formatting, might expect that value to come out as October 2, 2014.

However, you can convince SAS Enterprise Guide to observe the local customs, and here's how. Change your SAS Enterprise Guide shortcut to add a "/culture" argument, as in:

"c:\Program Files\SASHome\x86\SASEnterpriseGuide\6.1\SEGuide.exe" /culture:en-AU

The above example is for Australia. For British, try adding "/culture:en-GB". Here's the same date prompt with the new setting applied:

Any date value that you enter will be interpreted in the "Australian way" instead of the American way. This technique works for any version of SAS Enterprise Guide, 4.2 and later.

If you don't want to rely on a modified shortcut, you can set your "language" preference in Tools->Options. But first, you need to "fool" SAS Enterprise Guide into thinking that you have installed these additional English variations. Here's how.

  1. Using Windows Explorer, navigate to the installation directory for SAS Enterprise Guide.
  2. In the application folder, create a new empty folder with a name that matches the culture you want. For example, "en-GB" for British or "en-AU" for Australia.

    You can find the complete set of "culture names" on the Microsoft developer site.

When you restart the application, you will find new "language" options available on the list:

Select the one you like, restart the application, and immerse yourself in a new culture.

Post a Comment

SAS Talks: Favorite SAS Enterprise Guide Tricks

Last week's SAS Talks session, My Favorite SAS Enterprise Guide 5.1 Tricks, was remarkable in several ways.

First, the featured presenter was Marje Fecht, who also serves as the conference chair for SAS Global Forum 2014. She's an avid SAS professional who loves to educate her fellow SAS users on the best productivity tips and practices, including the use of SAS Enterprise Guide. As Marje points out, SAS Enterprise Guide is a primary topic of at least 20 presentations at the upcoming conference. You can see this for yourself in the easy-to-use conference scheduler, which allows you to slice-and-dice the agenda in many ways, including by SAS product.

The second remarkable thing about this SAS Talks session was the attendance. The number of connected participants was through the roof. It's a testament to Marje's star power and to the popularity of the topic. Did you miss it? The archive recording is available here and is free to view.

There was one more remarkable aspect to the session that I hope most attendees did not notice. On the day of the SAS Talks event, SAS headquarters was closed due to inclement weather in North Carolina. Aside from Marje (who was in sunny Florida), the session hosts and panelists were all snowbound in our respective homes. With an ice storm in the forecast, we hoped that our power and Internet connections would sustain us. And fortunately, they did.

I-Kong Fu, the product manager for SAS Enterprise Guide, followed Marje's presentation with a short demo of SAS Enterprise Guide 6.1 and a glimpse into some future developments for the next release of the product. While Marje and I-Kong were "on stage", my colleague Mark Allemang and I addressed many of the technical questions that participants submitted using the Q&A feature. In the remainder of this post, I've grouped the questions by topic and summarized the answers.

About the Data Explorer

Marje presented a thorough review of the interactive Data Explorer. According to Marje, the Data Explorer replaces a number of manual coding steps that analysts typically perform as they get acquainted with their data.

Q: Can I use the Data Explorer with WORK data sets?
A: The Data Explorer uses a special pool of utility SAS sessions (Workspaces) to perform its operations. Since these sessions can't share the WORK folder from your primary SAS session, the Explore option doesn't appear for WORK data. However, here's a trick... Submit this code within a SAS program node:

libname explorer &sasworklocation;

This will assign a new library (named "EXPLORER" in this case) to the same physical path as WORK, and you should be able to use the Data Explorer from that library.

Q: I don't see the Explore option on the menu, even for non-WORK data. Why not? Am I cursed?
A: Don't panic. Check whether you have the option "Automatically open data when added to project" disabled (in Tools->Options->Data General). If you disable that option, the Explore data feature becomes...hidden. See Problem Note 48487 for details.

Q: Can I use Data Explorer with DBMS tables in SAS/ACCESS libraries? Very large tables?
A: Yes, you can use this feature with any table in a library that you access with SAS. Behind the scenes, the Data Explorer runs PROC SQL and other descriptive-oriented SAS procedures to summarize data and produce "Quick Stats". Larger tables might take longer to generate results, but there isn't a hard limit on the size. You can configure the behavior of automatic Quick Stats to a maximum number of columns (default: 20) or data set rows (default: 10,000). See the SAS Enterprise Guide online help for more details.

When using a DBMS, your database administrator might have some opinions about how/when you should use this interactive exploration tool. A SAS administrator can limit this feature (using metadata roles/capabilities) if desired.

About the SAS Enterprise Guide projects and process flows

Marje showed how she was able to be more productive by organizing her work into projects, using process flows, built-in tasks, and notes. And I-Kong showed the new "sticky-note" style of process flow notes in the 6.1 version.

Q: When you create a Note in the process flow and then export a SAS program that you link to it, does the content appear as comments in the exported program?
A: No. The Note object isn't exported as part of the code, as it really annotates the process flow and not just the program. Using the Note object doesn't "excuse" you from adding useful comments in your code!

Q: In the SAS Enterprise Guide workspace, can you divide up your windows by monitor (if using multiple displays)?
A: No, not currently. Most of the SAS Enterprise Guide windows are constrained to the main application window, and cannot "float" to other monitors. This is something that the R&D team is exploring for a future release.

Q: When you select "Send to Excel" for a data set, is there a way to access the SAS program for that operation? Does it use SAS/ACCESS to PC Files?
A: The "Send To" mechanism does not actually use SAS code to do the work -- which is why you don't need the SAS/ACCESS product for this. Instead, SAS Enterprise Guide automates your local instance of Microsoft Excel and populates a new spreadsheet with the selected data set. This is just one of many ways to get your SAS content to Excel.

Q: Why doesn't the Query Builder task discover the table relationships from the database schema when adding two tables from the same database?
A: The relationships aren't always apparent from a SAS/ACCESS library. Right now, efficient queries do require some education on the part of the end user to know what keys/indexes to leverage. A database administrator can help users by defining SQL views that comprise the most commonly requested combinations.

About SAS programming


The program editor in SAS Enterprise Guide is syntax-aware, and provides keyword suggestions as well as automatic display of SAS library names, data set names, and even variable names as you type. It also provides a very handy code formatter that makes your programs (or those you "inherit" from colleagues) much more readable.

Q: Does the "autofill" work with the WHERE statement?
A: Yes (see picture). You can also call up a list of variables in the active data set with the Ctrl+Shift+V key combination. A full list of keyboard shortcuts is in the SAS Enterprise Guide online help (search the index for "keyboard shortcuts").

Q: Can I run just a selection of SAS code?
A: Yes. In the program editor, you can select the lines that you want to run, right-click and select Run Selection on (server) (or press F3 as a shortcut). Also, in a process flow you can select multiple program nodes (Ctrl+click), then right-click and select Run to run just those nodes. And don't forget about the File->New->Ordered List feature to create a list of program nodes to run in a prescribed sequence.

Q: Can I rely on all code being saved within a project?
A: You can decide: save the code in the project file (embedded) or store it on a file system as .SAS files. In the latter case, the SAS Enterprise Guide project holds a shortcut reference to the program file(s). And, you can mix and match -- with some embedded, some external files.

About SAS program versioning

I-Kong demonstrated some new features that are currently under development. One feature that generated much discussion was built-in "SAS program versioning", which keeps track of your SAS program revisions over time. I-Kong showed how you will be able to access the program history and compare differences over time. If this sounds interesting to you, take the time to watch the demonstration in the recorded SAS Talks session.

Q: Do I have to license WinMerge to see the SAS program differences?
A: No. WinMerge is free and that's what I-Kong showed, but you can use any file comparison/merge tool (for example, Beyond Compare or WinDiff).

Q: Is the program history linear or tree-structured?
A: In the history window you see it as a linear progression. However, you can go back to any "snapshot" in time and bring it back as the "current version" if you want to recover to a particular point. Under the covers, SAS Enterprise Guide is using a Git repository -- but no additional setup is needed on your part.

You'll hear more about this and other future developments at SAS Global Forum 2014, which now brings me to the final action item...

Don't stop learning: attend #SASGF14

Have you made your plans for SAS Global Forum? If not, it's the perfect time to take advantage of the Presidents Day Special. Through February 21, pay for one registration and you'll receive a discount code for 50 percent off of a second registration (both at the lower early-bird rates).

Post a Comment

Using Microsoft Visual Studio 2013 Express to debug custom tasks

It's true: you can use the Microsoft Visual Studio Express tools to build custom tasks for SAS Enterprise Guide and the SAS Add-In for Microsoft Office. And I said as much in my book, Custom Tasks for SAS Enterprise Guide Using Microsoft .NET. I even provided step-by-step instructions for how to get started with your first custom task.

The advantage of the Express editions is that they are free. You can download them from Microsoft's developer site and use them free-and-clear for 30 days. After 30 days, you must "sign in" to the tool with a Microsoft account, but the account is free too.

In my book, I also provided a stern caution about using the Express editions. While you could use the Express tools to build a .NET code library (DLL file) -- necessary for a custom task -- you had very few options for debugging it. The integrated debugger in the Express edition did not allow you to debug into an external application -- anything that you didn't build in the tool. Nor did the debugger offer the option to Attach To Process, which would have allowed you to start SAS Enterprise Guide, get your task loaded in, and then attach a debugging session to hit your breakpoints. And believe me, you will need the debugger.

With Microsoft Visual Studio Express 2013 the debugger integration has improved. You still can't "launch" an external application, but you can attach the debugger to an external process. And that's good enough to get the job done for custom task developers. (And remember -- even though my book didn't mention it -- you can use Visual Studio 2013 to build custom tasks for SAS Enterprise Guide 4.3 and later.)

To use Microsoft Visual Studio Express 2013 to debug your custom task:

Before you begin, make sure the PDB file (debug symbols file) is copied to the same directory as your custom task DLL. This will allow the debugger to sync up and find breakpoints.

With your task DLL in place (in one of the designated Custom folders where SAS Enterprise Guide searches), start SAS Enterprise Guide.

Then, with your task project open in Visual Studio, select Debug->Attach to Process.

In the Attach to Process window, find and select SEGuide.exe. (If you're working with the SAS Add-In for Microsoft Office, then the process you want will be Excel.exe, Winword.exe, or Powerpnt.exe.)

If you have breakpoints set in the debugger, you should find that they are hit (assuming that your task is working properly at that point). You should be able to view the contents of local and class variables in a Watch window. You can set debug options to "break on exception" to find tricky issues. In my book, I dedicate an entire chapter to debugging techniques that work especially well with custom tasks.

Obtaining the Express edition of Visual Studio

Here are some general steps to download the Express edition. I didn't provide exact links as I find those are subject to change, but this general navigation should get you there.

  • Visit VisualStudio.com, and select Downloads.
  • Look for the "Express" section; that's where you'll find the Express downloads. (Microsoft also offers trial periods for the professional editions -- if you want to give those a go.)
  • There are a few different flavors: one for Web, one for Windows 8, and one for Desktop.
    The specific version you want is Microsoft Visual Studio Express 2013 for Windows Desktop.

I still recommend the professional edition of Microsoft Visual Studio, especially if you're planning to build multiple custom tasks and maintain them over the long haul. Use the Express edition to experiment and dabble, and to explore whether custom tasks are a viable solution for your business problems. But if you continue with custom tasks, invest in the professional version. The professional editions provide even better debugging features, plus many productivity features that you'll appreciate, such as refactoring techniques, integrated profiling, unit testing, and more.

See also

SAS custom tasks: using Microsoft Visual Studio 2013 and other new toys
11 super-useful custom tasks for SAS Enterprise Guide
Custom tasks for SAS Enterprise Guide: Q&A

Post a Comment

Adding "sticky notes" in your SAS Enterprise Guide projects

This isn't the first blog post to laud the "Note" feature of SAS Enterprise Guide. You know, the feature that allows you to add documentation to describe what the heck your project or process flow is actually doing.

For example, Tricia described 3 useful ways to use the note feature. AnnMaria says it's a "godsend" for her, given her continuously interrupted life. Even I've mentioned it before within my advice about organizing your projects.

Your colleagues (or more likely, your future self) will thank you for using notes.

SAS Enterprise Guide 6.1 takes "Notes" to the next level. In a direct response to customer requests, the notes can now be arranged in your process flow just like the sticky notes on your desk. You can position them where you want, pin them, and resize them so you can see more content. They're beautiful.

Here's an example of the new look:

When you open an older project file in SAS Enterprise Guide 6.1, you might not see the new note style right away. That's because the conversion process doesn't want to disrupt your project's appearance without your permission. To expand an "old-style" tiny note into the more useful sticky note, right-click on the note and select Expand:

Would you like to learn more about new SAS Enterprise Guide features, plus glean real-world SAS Enterprise Guide tips from Marje Fecht (yes, that Marje -- SAS Global Forum 2014 chair)? Tune in next week for My Favorite SAS Enterprise Guide 5.1 Tricks, a free webinar in the SAS Talks series. Marje is the titled "My" person sharing the tips, and then I-Kong Fu will join her to showcase the 6.1 release.

Post a Comment

Reading and updating ZIP files with FILENAME ZIP

In a previous post, I shared an example of using ODS PACKAGE to create ZIP files. But what if you need to read a ZIP file within your SAS program? In SAS 9.4, you can use the FILENAME ZIP access method to do the job.

In this example, let's pretend that I need to analyze data that a government agency published (maybe by using SAS!) into a ZIP file. I've selected an exciting data source (found via data.gov) about Large Truck Crash Causation.

First, I need to download the latest version of the data file. I'll use PROC HTTP to do that job:

/* detect proper delim for UNIX vs. Windows */
%let delim=%sysfunc(ifc(%eval(&sysscp. = WIN),\,/));
 
/* create a name for our downloaded ZIP */
%let ziploc = %sysfunc(getoption(work))&delim.datafile.zip;
filename download "&ziploc";
 
/* Download the ZIP file from the Internet*/
proc http
 method='GET'
 url="http://ai.fmcsa.dot.gov/ltccs/Data/TEXT/Public/LTCCS_db_txt_public_01.zip"
 out=download;
run;

Next, I need to discover what files are within the ZIP file. I'll assign a fileref using the new FILENAME ZIP method. FILENAME ZIP is a directory-based access method, similar to the CATALOG access method or to using FILENAME to map to a folder. You can use functions such as DOPEN and DREAD to treat the ZIP file as if it's a file directory (since that's what it is, in concept).

/* Assign a fileref wth the ZIP method */
filename inzip zip "&ziploc";
 
/* Read the "members" (files) from the ZIP file */
data contents(keep=memname);
 length memname $200;
 fid=dopen("inzip");
 if fid=0 then
  stop;
 memcount=dnum(fid);
 do i=1 to memcount;
  memname=dread(fid,i);
  output;
 end;
 rc=dclose(fid);
run;
 
/* create a report of the ZIP contents */
title "Files in the ZIP file";
proc print data=contents noobs N;
run;

Here's the report of files within the ZIP archive:


I've identified the HAZMAT.TXT file as the one that I want to analyze. I peeked at the first couple of records and was able to scratch out a simple DATA step to read the data. Notice how I don't need to explicitly extract the HAZMAT.TXT file -- I can simply reference it as a "member" of the INZIP fileref. The ZIP access method does the rest.

/* Import a text file directly from the ZIP */
data hazmat;
 infile inzip(hazmat.txt) 
   firstobs=2 dsd dlm='09'x;
 input 
  CaseID $10.
  VehicleNumber 
  Material 
  Reportable 
  Waiver 	
  PSU	 
  PSUStrata	
  RATWeight;
run;
 
title "Box plot of Vehicles # per incident";
ods graphics / height=200 width=450;
proc sgplot data=hazmat;
	hbox vehiclenumber;
	label VehicleNumber="# of vehicles";
	xaxis labelattrs=(size=12) valueattrs=(size=12);
run;

SAS reads my data file successfully, and yields this interesting box plot from the SGPLOT step:


(It looks like most "hazardous materials" accidents involved just 2 or 3 vehicles, except for one messy outlier that had nearly 30. Imagine the cleanup effort on that one!)

As an alternative, if I know exactly which file I need, I can assign a direct fileref by using the MEMBER= syntax:

filename inzip zip "&ziploc" member="hazmat.txt";
 
/* then my INFILE references the file directly, no parenthesized-member */
data hazmat;
 infile inzip
   firstobs=2 dsd dlm='09'x;
/* ...  */

The ZIP access method isn't just for reading. I can also use it to create and update ZIP files. For creating ZIP files, I prefer to use ODS PACKAGE. But it's very handy to be able to update ZIP files from a SAS program without using an external tool. For example, here's a program that deletes an extraneous file from an existing ZIP file:

/* Remove the PackageMetadata piece that ODS PACKAGE creates */
filename pkg ZIP "c:\projects\filenamezip\new.zip" member="PackageMetaData";
data _null_;
 if (fexist('pkg')) then 
  rc = fdelete('pkg');
run;

Note: Like ODS PACKAGE, the FILENAME ZIP method does not support encrypted (password-protected) ZIP archives.

Download the complete SAS 9.4 program: filenameZipHttpExample.sas

Thanks to the growing size of data files, ZIP files are created and consumed by SAS users everywhere. Between ODS PACKAGE and FILENAME ZIP, you can teach your SAS programs to build and read the files without having to rely on external tools. The more you that you can use native SAS methods for this work, the more portable your SAS programs will be.

Post a Comment

Using SAS and ODS PACKAGE to create ZIP files

SAS users are big data consumers and big data creators. Often, we have to deal in large data files (or many smaller files) -- and that means ZIP compression. ZIP compression tools such as gzip, 7-Zip, and WinZip are ubiquitous, but they aren't always convenient to use from within a SAS program. To use an external ZIP utility you must issue a shell command via the X command or SYSTASK function, and that's not always possible within today's complex SAS environments.

Fortunately, SAS can read and write ZIP files directly. Ever since SAS 9.2, we've been able to create ZIP files with ODS PACKAGE. Beginning with SAS 9.4, we can read ZIP content by using FILENAME ZIP.

In this post, I'll review how to create ZIP files using ODS PACKAGE. I'll cover reading ZIP files with FILENAME ZIP in a future post.

Let's pretend that I'm working for a government agency, and that part of my job is to crunch some government data and publish it for the public. Of course, I'm using SAS for the analysis, but I need to publish the data in a non-proprietary format such as CSV. (It seems unbelievable, I know, but not every citizen is lucky enough to have access to SAS.)

First, I'll set up the output directory for this project. Since the ZIP file will contain a couple of files, including a subfolder, I want to mirror that structure here. The FEXIST and FDELETE functions will delete an existing ZIP file (perhaps left over from the last time I ran the process). The DLCREATEDIR option will create a "data" subfolder as needed. All of these mechanisms interact with the file system, but do not require XCMD privileges. This means that they'll work in SAS Enterprise Guide and stored processes.

%let projectDir = c:\projects\sgf2013\filenamezip;
 
/* Clean slate! */
filename newfile "&projectDir./carstats.zip";
data _null_;
  if (fexist('newfile')) then 
  	rc = fdelete('newfile');
run;
filename newfile clear;
 
/* Create folder if it doesn't exist */
options dlcreatedir;
libname out "&projectDir./data";

Next, I need to create the content to include in the ZIP file. In this scenario, I'm crunching some heavy-duty numbers about Cars data, and then putting the results into a CSV file. Then I'm creating a README file in RTF format; the document contains a simple data dictionary plus instructions (such as they are) for using the data. I used ODS TEXT to throw in some ad-hoc text among the SAS output.

/* Create some data */
filename newcsv "&projectDir./data/pct.csv";
proc means noprint data=sashelp.cars;
var msrp;
output out=out.pct median=p50 p95=p95 p99=p99;
run;
ods csv file=newcsv;
proc print data=out.pct;
format _all_; /* clear the formats */
run;
ods csv close;
 
/* Create an informative document about this package */
filename rm "&projectDir./readme.rtf";
ods rtf(readme) 
  file="&projectDir./readme.rtf" style=Printer;
ods rtf(readme) 
  text="These are some instructions for what to do next";
proc datasets lib=out nolist;
contents data=pct;
quit;
ods rtf(readme) close;

Finally, I'm going to take those results and package them in a ZIP file. The ODS PACKAGE mechanism was originally designed to share results from a SAS stored process. By default, it adds a PackageMetaData entry that a consuming SAS application could use to interpret the result. In this case we don't need this entry; the NOPF option suppresses it.

Notice that I specify the PATH= option to place the CSV file in the "data" folder within the archive. As soon as the ODS PACKAGE CLOSE statement executes, the ZIP file is created.

/* Creating a ZIP file with ODS PACKAGE */
ods package(newzip) open nopf;
ods package(newzip) add file=newcsv path="data/";
ods package(newzip) add file=rm;
ods package(newzip) publish archive 
  properties(
   archive_name="carstats.zip" 
   archive_path="&projectDir."
  );
ods package(newzip) close;

Here's a screen shot of the ZIP file opened in WinZip:

That's it! I can add any file that I want to the ZIP archive; I'm not restricted to files that were created by SAS. This makes it easy to use SAS as an automated method to update data archives regularly, creating user-friendly packages for consumers to make use of our data.

Note: A common question: does ODS PACKAGE (and FILENAME ZIP) support password-protected ZIP files (encryption)? The answer is No. If that's a requirement, you'll need to use an external package such as 7-Zip.

Download the complete program (SAS 9.3 or later): createZipODSPackage.sas

You might also enjoy:

Post a Comment

Customer segmentation using RFM in SAS Enterprise Guide

Recency, Frequency, and Monetary Analysis (or RFM) is a popular customer segmentation technique employed by database marketers everywhere. Marketers use RFM to identify which customers are most likely to respond to a direct marketing campaign. The model takes into account three simple metrics:

  • How recently did the customer buy from you?
  • How frequently does the customer buy something from you?
  • How much money does the customer spend on your products?

Each metric receives a value of 1 through 5. The result is 125 "bins" of customers (because 125 is 53). Those with higher RFM scores are considered more likely to respond to a campaign...potentially.

For years, SAS customers have used special tools like SAS Enterprise Miner to compute RFM. With SAS 9.4, the RFM algorithms are built into Base SAS, and there's an easy-to-use task in SAS Enterprise Guide. (The task is also available in the SAS Add-In for Microsoft Office.) You can find the task in the menus at Tasks->Data Mining->Recency, Frequency, and Monetary Analysis.

Note: To use the task, you must have SAS 9.4 and SAS Enterprise Guide 6.1 (or SAS Add-In for Microsoft Office 6.1). Despite the "Data Mining" category, this task does not require SAS Enterprise Miner.

As an example, suppose you have transaction data that looks like the following. You need only the 3 fields -- a customer ID, a transaction date, and a transaction amount (value):


From this, RFM calculates "scores" for each customer. The customers with the highest scores will probably be those that spent the most with you, across the most recent and frequent dates. The idea behind RFM is that a minority of customers are responsible for a majority of your business. RFM scores provide visibility into who those valuable customers are. Here's an example of the scored data, summarized at the customer level:


The RFM task supplies several useful charts. Here's a "monetization map", which summarizes the monetary values for each combination of frequency and recency scores. You might use this to help identify a "sweet spot" of customers that you want to target.

Next, let's look at a paneled bar chart of the Frequency by Recency segments. The bar on the lower right corner indicates that there are a handful of customers who made several purchases in the past (high frequency), but that was a long time ago (not recent). Perhaps that's a good target segment for a "Come back and see us -- we miss you" campaign. Contrast this with the bar on the upper right, which shows the 60 superfans: the customers who bought lately and often. You can decide whether to "go back to the well" with this group in the next campaign, or save the campaign expense as they might buy from you anyway, without prompting.

RFM scores are just one small part of planning a campaign. The "Recency, Frequency, and Monetary Analysis" task is a good start, but eventually you might want to factor in other criteria.

After all, direct marketing has many nuances, such as cross-referencing with opt-out lists and taking steps to avoid "overmarketing" to any one segment. Tracking response rates, testing campaigns, and the actual campaign workflow are also essential elements. When you're ready, SAS Customer Intelligence offers an integrated set of applications for all of these aspects.

Post a Comment