Sunday, March 6, 2011

Making SAS Interactive (Part 2): Using %window and %display

Its the world of GUI. And you are left nowhere if you don't provide the users, the luxury (or rather fulfill the basic needs) of giving a Graphical User Interface. This holds good even for SAS.

SAS came up with the tool called SAS/AF and SAS EG which provides the users with a brilliant GUI and thus making their lives so eeaasssy.. However, not many of us would have bumped into this brilliant macro tool called %WINDOW and %DISPLAY which is present in BASE SAS9 which satisfies the basic needs of having a GUI. Here I take a small dive into the SAS ocean again, exploring the functionalities of these two macros.

%WINDOW: This creates the basic window that needs to be popped up upon execution. We can specify the window attributes here like the color/width/height,etc. You could also specify the position of the text that is to be displayed and the input parameters that are to be read.

%DISPLAY: This actually invokes the window that has been defined in the %window program.

Below is a simple illustration of the %window and %display invocation:

%window test_win color=blue

/*dimension for the window*/
icolumn=15 irow=10
columns=90 rows=45


/*Content of the window*/
#3 @25 "My Window"
attr = rev_video
#5 @10 "Hello Pramod"
attr = underline
;


%display test_win;

The above code displays the output as shown below:



Below, I've demonstrated how we can use this to make SAS interactive. Most of the code is self explanatory, of course with a bit of help from the support.sas.com documentation available at: http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000206734.htm

/* Main window */

%window final color=gray

/*dimension for the window*/
icolumn=15 irow=10
columns=90 rows=75


/*Content of the window*/
#1 @25 "&error_msg"
#3 @15 "Hi &sysuserid." attr = rev_video color=blue @60 "Date: &sysdate9." attr = rev_video color=blue
#5 @25 "Welcome to the Reporting World" attr = rev_video

#8 @35 "Report List"
#11 @15 "1. Class listing" @50 "2. Class Report by Gender"
#13 @15 "3. Class Report by Age" @50 "4. Class freq"
#16 @15 "Enter your Choice:" @35 choice attr=underline
;


/* End of Window Final */

%macro execute;
%let choice=;%display final;

%if &choice=1 %then %do;
 proc print data=sashelp.class noobs;
 run;
%end;
%else %if &choice=2 %then %do;
 proc report data=sashelp.class nowd;
 columns sex height weight;
 define sex / group;
 define height /analysis;
 define weight / analysis;
 run;
%end;
%else %if &choice=3 %then %do;
 proc report data=sashelp.class nowd;
 columns age height weight;
 define age / group;
 define height /analysis;
 define weight / analysis;
 run;
%end;
%else %if &choice=4 %then %do;
 proc freq data=sashelp.class;
 tables sex*age /nocum nopercent;
 run;
%end;
%mend execute;

%execute
In the above code, I first display a list of things the use might be interested to see in the %window, and then %display this inside the macro execute. I also read his input into the macro variable choice and then based on his selection, I call the required procedure inside the macro execute.

The output of the above code is as shown below:


Upon entering the value 2 and hitting the enter button, we get the output as shown:




You could experiment more on this and let me know your suggestions/thoughts/ideas...

10 comments:

  1. %window and %display are certainly good "old school" methods for displaying window prompts and displays in SAS Display Manager.

    However, these methods work only when running in the SAS windowing environment (display manager). They can't work from batch or when SAS is running as a "headless" server (for example when running SAS Enterprise Guide).

    ReplyDelete
    Replies
    1. You can launch from a desktop shortcut pointing to a DOS batch command file.

      Delete
    2. Another option is to launch from inside a text editor like TextPad when you set up 'Tools' that will launch the current open file with the program of your choice.

      Delete
  2. Hi Chris,

    I wasn't aware that %window/%dislpay was that old a method. Thought it was added recently to the SAS system...

    Also could you please throw some light on the way SAS runs in SAS Enterprise guide. I quite din understand when you meant "headless" server. I was under an assumption that when a job is submitted in EG, it automatically sends this code to the SAS server for execution... Could you please explain me how this works or at least refer me to some documentation if any??

    Thanks so much in Advance!!

    ReplyDelete
  3. This sounds Fantastic. never tried this stuff.. Also can it be possible to output the window content with all the jazzy stuff to a file (may be as an image) ???

    ReplyDelete
  4. I have a couple of macros that make SAS more interactive in interactive mode: CheckLog and OpenTable. CheckLog checks the log for issues and can be run from a keyboard shortcut. OpenTable can be too, and it does what it says, and without an argument, it tries to open the last table, and if the paste buffer has a table in it, it will try to open that too. When there's a conflict, it asks which to open using a Windows API or the %window statement. Try them out and let me know what you think:

    http://sas.cswenson.com/macros

    http://sas.cswenson.com/macros/CheckLog.sas?attredirects=0&d=1

    http://sas.cswenson.com/macros/OpenTable.sas?attredirects=0&d=1

    ReplyDelete
  5. Hello Chris!

    Wow!!! I must say thats a brilliant compilation of macros! Haven't gone through this completely but its truly remarkable!!!

    I would start reading through each of them as and when i get time.. I i might as well use a couple of them if it fits in any of my processes!!

    Thanks so much for sharing this link!!

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. I’m fascinated this informative write-up. You can find so a lot of points mentioned here I had never thought of before. You might have produced me realize there is more than 1 way to take into consideration these points….sas online training

    ReplyDelete