Jedi SAS Tricks - Make This a Button in Base SAS

3
Jedi SAS Tricks - Execute your SAS code from a custom toolbar button! Click To TweetA recent post, Jedi SAS Tricks: The DATA to DATA Step Macro, engendered a lot of response on Twitter. One of the re-tweets included a call to action - make this a button in Base SAS!

Tweet says "Make this a button in base SAS"
Well, Sam, I aim to please! Now, I'm not the guy who builds the SAS Windowing Environment interface, but if you are running PC SAS, I can show you how to customize your tool bar to do just that: make this macro execute from a button.  First, we'll change the name of this macro to Data2DataStepButton and I'll add a bit of code to the beginning of the macro to provide a dialog box to accept input for the macro parameters. Make sure to save the code for this macro to a file named data2datastepbutton.sas somewhere in your SASAUTOS path. The remainder of the code is the same as the original Data2DataStep macro.

%macro Data2DataStepButton(dsn,lib,file,obs);
   %local varlist msgtype ;
   %window Data2DataStep columns=80 rows=20
   # 3 @ 6 'Libref:                 ' lib 41 attr=underline 
   # 5 @ 6 'Data Set:               ' dsn 41 attr=underline 
   # 7 @ 6 'Program file name:      ' file 50 attr=underline
   # 9 @ 6 'Number of Obervations:  ' obs  3 attr=underline
   #12 @ 6  'Press ENTER to continue';
%display Data2DataStep;
...

Now let's customize the toolbar in PC SAS to add a button that executes this macro.
Step 1: Right click on an empty spot on the SAS toolbar, and choose "Customize" from the pop-up menu.
Step 2: In the dialog window, choose the Customize tab.
Step 3: Use the Add Item button to add a new separator and a blank tool at the bottom of the list. You can use the up/down arrow buttons to re-arrange items if necessary.
Step 4: Choose an icon to display on the toolbar using the Icon Select button.
Step 5: Give your new tool a title, command to execute and some tool tip text to make it easier to remember what the button does. When finished, the dialog will look something like this:

Toolbar Customize Dialog Box Step 6: Click OK and, when asked if you want to save your changes, click Yes. Your new button should appear on the SAS toolbar.

New toolbar button on the SAS window toolbar

To test your button, click on it! The macro dialog will appear. Fill in some values and press ENTER to generate your SAS program:

Data 2 Data Step Macro Dialog Window

WooHOO - we've made our own custom tool button in Base SAS! As usual, you can download the SAS code (and a PDF copy of these instructions) here.

Until the next time, may the SAS be with you!
Mark

 

 
Share

About Author

SAS Jedi

Principal Technical Training Consultant

Mark Jordan (a.k.a. SAS Jedi) grew up in northeast Brazil as the son of Baptist missionaries. After 20 years as a US Navy submariner pursuing his passion for programming as a hobby, in 1994 he retired, turned his hobby into a dream job, and has been a SAS programmer ever since. Mark writes and teaches a broad spectrum of SAS programming classes, and his book, "Mastering the SAS® DS2 Procedure: Advanced Data Wrangling Techniques" is in its second edition. When he isn’t writing, teaching, or posting “Jedi SAS Tricks”, Mark enjoys playing with his grand and great-grandchildren, hanging out at the beach, and reading science fiction novels. His secret obsession is flying toys – kites, rockets, drones – and though he usually tries to convince Lori that they are for the grandkids, she isn't buying it. Mark lives in historic Williamsburg, VA with his wife, Lori, and Stella, their cat. To connect with Mark, check out his SAS Press Author page, follow him on Twitter @SASJedi or connect on Facebook or LinkedIn.

Related Posts

3 Comments

  1. Pingback: Jedi SAS Tricks: DIY Tasks in SAS Studio - SAS Learning Post

    • SAS Jedi

      An excellent choice for Enterprise Guide users! My next blog will create a custom task for SAS Studio that does the same thing, then we'll have all the major interfaces covered :-)

Back to Top