4
Aug

Viewing SAS catalogs and formats in SAS Enterprise Guide

Many years ago I shared a custom task that allows you to view and manage SAS catalogs within SAS Enterprise Guide. As a reminder, a SAS catalog is a special type of SAS file that acts as a container, like a folder, for a variety of content items called catalog entries. Conceptually, this is like a folder in a file system with a diverse collection of file types. The entries and their uses are specific to SAS, and they include things like SOURCE (program code), SCL (SAS Component Language) programs, SAS format definitions, compiled SAS macro programs, and more.

Most catalog entries aren't that interesting for SAS Enterprise Guide users -- with the notable exception of SAS format definitions. Beginning with the day that I shared the task on my blog, my readers began asking for the ability to see inside a SAS format definition. I replied, "great idea! I'll put that on my to-do list." Here it is, 7 years later -- and I've got it done. I am a man of my word.

>> Download the task from here (ZIP file, with README text file instructions)

Pay special attention to the README instructions to deploy the correct version, and make sure you unblock the task DLL if needed.

And more good news -- this task is scheduled to ship as a built-in task (on the Tools menu) in the next release of SAS Enterprise Guide, coming soon. The custom task download will support SAS Enterprise Guide versions 4.3 through 7.13. Later versions will have the task already available!

Key features of the Catalog and Formats Explorer

Like the original task that I shared, this revised task allows you to explore SAS libraries and the catalogs that they contain. You can view the metadata about every catalog entry -- name, type, description, created and modified dates. You can also delete entries that you need to clean up. And you can view the contents of certain types of entries, mainly SOURCE entries and the format entry types. Here are the main enhancements:

  • You can view the contents of FORMAT, FORMATC, INFMT, INFMTC entries
  • The window displays “modeless” – you can have it showing while you still work on other tasks, such as your SAS programs. Define a format in code, run it, and then click Refresh in the task to see it.
  • You'll find special entry for "User-defined formats", which shows just the catalogs that contain format definitions within the FMTSEARCH path. You can still navigate any library to find catalogs that contain formats.

Here's a screenshot of the task. You can also watch my 5-minute video demonstration of the task in action on SAS Support Communities.

For developers: How it was built

Since the original task was shared as a companion example for my custom tasks book, I've also shared the source code that goes into these enhancements. You can find these in the same GitHub repository that contains the original version. Adding these enhancements makes use of other techniques that I've already shared on this blog.

To generate a text report of a format definition, the task submits a PROC FORMAT step with a SELECT statement. Here's an example:

filename fmtout temp;  
%let _catexp1 = %sysfunc(getoption(center));  
%let _catexp2 = %sysfunc(getoption(date));  
%let _catexp3 = %sysfunc(getoption(number));  
%let _catexp4 = %sysfunc(getoption(pagesize));  
options nocenter nodate nonumber pagesize=max;  
ods listing file=fmtout; 
proc format fmtlib lib=dbmlnx.formats; 
 select ab; 
run; 
ods listing close; 
options &_catexp1. &_catexp2. &_catexp3. PS=&_catexp4.;

With the listing file generated, the task uses code similar to this Windows PowerShell example to download the contents of the output. You might notice that the SAS code sets a few system options, but it stores and later replaces the option values so that your other programs won't be affected.

If you like to tinker, feel free to download the source code and see how it works. If you want to learn more about custom tasks in SAS Enterprise Guide, view my Ask the Expert session, available on-demand from here.

The post Viewing SAS catalogs and formats in SAS Enterprise Guide appeared first on The SAS Dummy.

14
Nov

The Copy Files task is going legit (and moving)

I've supplied dozens of custom tasks for SAS Enterprise Guide, but the Copy Files task is easily the most popular. The Copy Files task allows you to capture "file transfer" steps inside your process flow, so that you can automate any file upload and download operations between your PC and your SAS workspace session. It has proven to be an essential task for customers who move from using PC SAS to SAS Enterprise Guide. Many of you still need a method to copy data and results to and from your SAS session. When the SAS session is on a remote server, then this task fills that important gap.

Because "Copy files" is a custom task, you have to download the task package (from this blog) and follow a few steps to install the task into your SAS Enterprise Guide environment. When installed, the task can be found in the Tools → Add-In menu.

Copy Files task moves to the Tasks → Data menu

Copy Files in new menuThat's about to change with the next release: SAS Enterprise Guide v7.13. We're going to make an honest task out of "Copy Files," as it becomes an official feature in SAS Enterprise Guide. That's great news for a couple of reasons: no more custom install steps, and you can now get official support from SAS Tech Support when using it (although they would have always helped before now). The task works exactly the same way and if you have existing projects that use it, you don't need to make any changes. However, there is one change you need to know about: as an "official" task, it will appear in an official menu location. As of SAS Enterprise Guide 7.13, you'll find Copy Files in the Tasks → Data menu, near the bottom with some other utility-type tasks. And if you had previously installed it as a custom task, it will no longer appear in the Tools → Add-In menu.

SAS Enterprise Guide 7.13 is set to release within the next couple of weeks (near the end of November 2016), and it contains several exciting new features that I'll describe in this blog. Many of you will see it immediately when SAS Enterprise Guide prompts you to update. Stay tuned!

tags: Copy Files, SAS custom tasks, SAS Enterprise Guide

The post The Copy Files task is going legit (and moving) appeared first on The SAS Dummy.

20
Feb

A custom task to list and stop your SAS sessions

Last week I described how to use PROC IOMOPERATE to list the active SAS sessions that have been spawned in your SAS environment. I promised that I would share a custom task that simplifies the technique. Today I'm sharing that task with you.

How to get the SAS Spawned Processes task

You can download the task from this SAS communities topic, where I included it as an attachment. The instructions for installation are standard for any custom task; the details are included in the README file that is part of the task package.

You can also view and pull the source code for the task from my GitHub repository. I built it using Microsoft .NET and C#.

How to use the SAS Spawned Processes task

Once you have the task installed, you can access it from the Tools->Add-In menu in SAS Enterprise Guide. (By the way, the task should also work in the SAS Add-In for Microsoft Office -- though the installation instructions are a little different.)

The task works by using PROC IOMOPERATE to connect to the SAS Object Spawner. You'll need to provide the connection information (host and port) plus the user/password for an account that has the appropriate permissions (usually a SAS admin account). Note that the port value is that of the Object Spawner operator port (by default, 8581) and not the SAS Metadata Server.

spawnedprocesses
The task shows a list of active SAS processes. Of course, you're using a SAS process to even run the task, so your active process is shown with a yellow highlight. You can select any of the processes in the list and select End Process to stop it. You can drill into more detail for any selected process with the Show Details button. Here's an example of more process details:

processprops
Did you try the task? How did it work for you? Let me know here or in the SAS communities.

Custom task features within this example

If you're professionally interested in how to build custom tasks, this example shows several techniques that implement common requirements. Use the source code as a reference to review how these are built (and of course you can always refer to my custom tasks book for more guidance).

  • Submit a SAS program in the background with the SasSubmitter class. There are two examples of this in the task. The first example is an asynchronous submit to get the list of processes, where control returns to the UI and you have the option to cancel if it takes too long. With an asynch submit, there are some slightly tricky threading maneuvers you need to complete to show the results in the task. The second example uses a synchronous submit (SubmitSasProgramAndWait) to stop a selected SAS process.
  • Read a SAS data set. The SAS program that retrieves a list of processes places that result in a SAS data set. This task uses the SAS OLE DB provider to open the data set and read the fields in each row, so it can populate the list view within the task.
  • Detect errors and show the SAS log. If the SAS programs used by the task generate any errors (for example, if you supply the wrong credentials), the task uses a simple control (SAS.Tasks.Toolkit.Controls.SASLogViewDialog) to show the SAS log -- color-coded so the error is easy to spot.
  • Retrieve the value of a SAS macro variable by using SasServer.GetSasMacroValue("SYSJOBID"). This pulls the process ID for your active SAS session, so I can compare it to those retrieved by PROC IOMOPERATE. That's how I know which list item to highlight in yellow.
  • Save and restore settings between uses. Entering credentials is a drag, so the task uses a helper class (SAS.Tasks.Toolkit.Helpers.TaskUserSettings) to save your host/port/user information to a local file in your Windows profile. When you use the task again, the saved values are placed into the fields for you. I don't save the password -- I'm sure that I'd get complaints if I did that, even if I encoded it.
tags: IOMOPERATE, sas administration, SAS custom tasks, SAS Enterprise Guide

The post A custom task to list and stop your SAS sessions appeared first on The SAS Dummy.

28
Oct

Copy SAS variable names to the clipboard in SAS Enterprise Guide

I recently met SAS user "CSC" at the Analytics 2015 conference. It might be generous to say that he's an avid user of SAS Enterprise Guide; it's probably more accurate to say that he's now accustomed to the tool and he's once again productive. But he still misses some features from his PC SAS days, including this one.

He wants to be able to copy just a list of SAS variables names from a SAS data set, so that he can then paste them into a SAS program (or another document). In PC SAS he had a simple GSUBMIT sequence that captured the names and "copied" them to the Windows clipboard with FILENAME CLIPBRD. That does not work in SAS Enterprise Guide, because SAS doesn't have direct access to the clipboard on your local machine.

CSC posted his question to the SAS Enterprise Guide community, and Tom suggested that a custom task might help. Good answer, but there it sat until CSC and I met in person this week in Las Vegas. After a short discussion and a personal plea, I was able to create the task in about 30 minutes.

copycolsmenu
Actually, it's three tasks, to cover three variations of the "Paste" operation. One supports a CSV-style, another supports CSV over multiple lines, and a third produces just a straight list on separate lines with no commas.

threecopytasks

You can download and try this custom task too. It works with SAS Enterprise Guide 4.3 and later. Download the task from the SAS support site as a ZIP file. The instructions for installation and use are in the README.txt in the ZIP file.

Related articles

tags: SAS Communities, SAS custom tasks, SAS Enterprise Guide

The post Copy SAS variable names to the clipboard in SAS Enterprise Guide appeared first on The SAS Dummy.

11
Jun

Ask the Expert: Creating custom tasks for SAS Enterprise Guide

If you have not yet discovered the new Ask the Expert series on the SAS Training site, you are missing out on a treasure. Visit the site right now and review all of the available topics, from "Newbie" to Analytics to Visualization to good ol' SAS programming. Go on; I'll wait.

Ask the Expert - they wear glasses, apparently
Welcome back! Amazing, right? You can get lost for hours learning new stuff or just reviewing what you thought you already knew. Some topics are available as live sessions that you can "attend" as they happen, but many of them are available on-demand, for free, no strings attached.

You might have noticed that I have a humble contribution in the "expert" collection: Developing Custom Tasks for SAS Enterprise Guide. During the 37-minute video, I lead you through the uses of SAS custom tasks and the basic steps for creating your own task. You'll learn what custom tasks can do and what they cannot do. You'll learn about the tools and APIs that support the creation of tasks. And you'll see the "inside" of a completed custom task project. (An aside: I owe a big "thank you" to the team that post-processed the recording of my expert talk -- I know that I wasn't that smooth and concise when I recorded it!)

It's a short introduction and watching it won't make you an expert in the topic, but it will help you to decide whether to learn more. You can learn more from my book on this topic, or you can arrange to attend an offering of the two-day course that we offer occasionally. Or you can learn it all on your own, as many have. There are plenty of examples and references to work from. If you're wondering what skills you should have before taking the class, watch my "about this course" video here.

In the "ask the expert" video, I referenced a collection of API libraries that make it easier to set up your custom task projects. These API libraries are available for each version of SAS Enterprise Guide, and they allow you to create tasks that are compatible with multiple versions of the SAS applications, even if you do not have those particular versions installed. (You still need at least one version of SAS Enterprise Guide or SAS Add-In for Microsoft Office in order to test and run your custom task.)

With the permission of the SAS R&D developers, I have made those libraries available here:

>> Download custom task API libraries (ZIP file 333KB)

The README.txt file in the ZIP file explains how to use the libraries.

If you have questions as you start your custom task adventures or if you just want to brag about your successes, post back here or on the SAS Enterprise Guide community. I'd love to hear from you!

tags: SAS custom tasks, SAS Enterprise Guide, sas training

The post Ask the Expert: Creating custom tasks for SAS Enterprise Guide appeared first on The SAS Dummy.

12
Mar

Project Reviewer task and Copy Files task: refreshed for v7.1

Two popular SAS custom tasks have recently been updated for SAS Enterprise Guide 7.1. Most custom tasks that I've shared will work without modification across releases, but these two required a special rebuild due to some internal product API changes.

The Project Reviewer task allows you to see a detail view of the tasks/programs within your SAS Enterprise Guide process flows. The listing shows the task names and types, when they were added to the project and last modified, and how much time they take to run. You can also create a SAS-based ODS report from the data, which is a great way to use SAS Enterprise Guide to report on your SAS Enterprise Guide project. (Wow, that's so meta!)

projectrev71
Download Project Reviewer: See this blog post for more information and download link

The Copy Files task is used to move files from your local PC to your SAS session, or from your SAS session to your local PC. This allows you to capture these file transfer steps within your process flow so that they are repeatable. The task supports the use of macro variables and wildcards, which gives you lots of flexibility when designing a process in which the file names and quantities are subject to change.

Copy Files task
Download Copy Files: See this blog post for more information and download link

If you use these tasks (or other custom tasks) and find them useful, please leave a comment! I love to hear how the tasks are being used. And sometimes useful custom tasks find their way into the actual product in a future release. Your feedback is important to help to make that happen.

Other related articles

tags: Copy Files, process flows, SAS custom tasks, SAS Enterprise Guide
16
Feb

Can you learn how to create custom tasks?

To develop a custom task for use in SAS Enterprise Guide (or SAS Add-In for Microsoft Office), you need a few things:

  • A working knowledge of SAS and SAS Enterprise Guide
  • Microsoft Visual Studio (the free Express edition will do, though the Professional edition is better)
  • Some experience with C# or Visual Basic -- or at least with an object-oriented framework such as Java or C++.

It helps to have a "how to" guide, and I've written one of those. And if you're the sort of person who learns best in the classroom, you can now take a class.

Are you wondering whether the class right for you? Watch this video (about 4 minutes long, in which I do my best Troy McClure impersonation). I'll explain what custom tasks are and what you need to know in order to build them. I'll also explain what you can expect to learn from the class, and the skills you should have before you enroll.


To enroll:
Visit the support.sas.com SAS Training site and find an offering that works with your schedule and location.

tags: .net, SAS custom tasks, sas training
12
Jun

New course: Developing Custom Tasks for SAS Enterprise Guide

This probably won't surprise any of my regular readers: "SAS custom tasks" is one of my favorite topics to talk about.

Since 2007, I've written blogs about how you can use custom tasks to extend SAS Enterprise Guide and the SAS Add-In for Microsoft Office. I've shared lots of examples, many that you can use simply "as-is" without any special technical knowledge. I presented a SAS Talks webinar on the topic. And I even wrote the book: Custom Tasks for SAS Enterprise Guide Using Microsoft .NET.

Now I'm ready to take this show on the road, and teach this topic in a classroom setting. I've built a new SAS course: Developing Custom Tasks for SAS Enterprise Guide.

I taught the course for the first time this past April. All new SAS courses go through a "test teach", in which internal SAS folks participate as students. The purpose of a test teach is to ensure that the course materials, software setup, and instructor are all up to the high standards for SAS Training offerings. In my test teach, I had students from Technical Support, R&D, Product Management, Education, and Professional Services. That's a pretty good mix, and I got some good feedback. At the end, we agreed that the course is ready for prime time.

Here are some high-level features that you can expect from the course:

  • It's a two-day course -- and we fill the time!
  • We cover the SAS APIs and toolkits that make custom tasks possible. We also cover best practices for design and build, which make it much easier to have successful custom task projects.
  • Students will get plenty of hands-on experience, some as instructor-led tutorials and some as independent lab exercises.
  • You will build a complete custom task, in class!
  • You don't need to be a SAS expert or Microsoft .NET expert coming in, but I recommend that you have base SAS programming experience and also experience with some object-oriented development tool, such as Microsoft Visual Studio (C# or Visual Basic) or Eclipse (with Java).
  • You should come having at least working knowledge of SAS Enterprise Guide.

If all of this sounds interesting to you, I hope to see you in a SAS training center in the near future! Check the SAS Training & Books web site for schedules and locations. (Note, this link is from the USA course catalog. Other countries might add the course later, based on interest. Hint, hint.)

tags: SAS custom tasks, sas training
11
Feb

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

tags: .net, SAS custom tasks
4
Dec

SAS custom tasks: using Microsoft Visual Studio 2013 and other new toys

Writing a book about SAS (or any computer software) is both gratifying and frustrating. It's gratifying because there are so many SAS users in the world, and it feels good when you can share your expertise with them. It's also gratifying to have a volume that you can point to and say "I wrote that!"

But it's frustrating too, because computer software changes rapidly, and your book can quickly become out-of-date. Some people might call that "job security". Unfortunately, constantly revising and republishing my books isn't part of my "day job", and while rewarding in many ways, it doesn't pay the bills.

When we published Custom Tasks for SAS Enterprise Guide using Microsoft .NET, the current versions of software were:

  • SAS Enterprise Guide 5.1
  • SAS 9.3
  • Microsoft Visual Studio 2012 (very recently released at the time!)

In just 11 months since then, we are now working with SAS 9.4, SAS Enterprise Guide 6.1, and Microsoft Visual Studio 2013. I don't address these versions in my book. So readers wonder: can you use the book with the later editions of software?

The answer is Yes. The material in the book still applies, one-hundred-percent. You need to adjust the book instructions only in the most obvious ways. That is, where there is an instruction that includes a specific version number (a folder name, for example), you need only to substitute the more recent version number.

The Microsoft Visual Studio templates, which I provide as a simple way to bootstrap your custom task project, still work as they always have. I originally designed them to work with Microsoft Visual Studio 2008 and SAS Enterprise Guide 4.2. Since most users are well beyond those versions now, I've created an updated set of templates that work better with Microsoft Visual Studio 2010 and later, and SAS Enterprise Guide 4.3 and later. You can find the updated Visual Studio templates on the SAS support page for custom tasks. The download package includes templates for C# and Visual Basic, plus illustrated instructions for installation and use. The templates work with the 2010, 2012, and 2013 editions of Microsoft Visual Studio, including the free Express editions.

Custom task project in VS2013

Note: while you can use the free Express editions of Microsoft's development tools, I always recommend the professional editions for serious long-term work. The professional editions include better support for debugging task code, a feature that I find to be essential for production work.

tags: .net, SAS custom tasks
Back to Top