Create User Interface (UI) in SAS

How to  create a User interface SAS ? 

Often, People make a front end with Java, .Net, Python etc. and integrate SAS at back-end for processing. But people often are unaware of the fact that SAS also offers an in-built facility to create "very basic" UI . let's learn it and see if you can use it somewhere in your protect implementation.It is very simple and one might find it very useful in his/her project.

We define the code into two parts :

1. Task Window :  The portion of code in which you do whatever you want to achieve with the code. Essentially, there are few macro variables that we don't call with the regular method. We rather use the UI method to do so in this.

2. Execution Window : The code prompts the User Interface (UI) window and ask for inputs of user and these inputs are nothing but the values we assign to macro variables, defines in the Task Windw portion.

Task Window

%Macro automation(Class,param,parent_data,filter,filter_value);

Proc SQL print;
Create table demo as
select &Class., Mean(&param.) as Average_&param.
where &filter. = &filter_value.
group by &Class.;

Proc print;run;


In the above Macro, we are summarizing a subset of data at a particular level. We have kept parent dataset name, group by variable, summary variable, filter variable, and filter criteria dynamic with the help of macro variables. We are going to call these (local) macro variables in the execution window now.

Execution Window

%Macro start_me;

/* All the macro variables, present in the Task window, have been defined as global macro variables first */

%global Class param parent_data filter filter_value;

/* we define a prompt window with a name "first". Name is not of much use. */

%window first

/* here we write, how the UI would be like */

#3 @45 "Define Query criteria" color=blue
#6 @5 "Input details here" color=blue //
@5 'Select Data Name' color=black +2 parent_data 83 color=green required=yes  attr=underline //
@5 'Select Class Variable' color=black +2 Class 25 color=green required=no attr=underline //
@5 'Select parameter to be summarized' color=black +2 param 25 color=green required=no attr=underline //
@5 'Select filter column' color=black +2 filter  25 color=green required=no attr=underline //
@5 'Select filter value' color=black +2 filter_value 25 color=green required=no attr=underline
%display first ;

/* and now it's time to call the macro in Task Window */


%Mend ;

How to interpret the line written in UI part ?

How does the prompt looks on execution?

Then user is required to give inputs, as shown below :

And here is the output  >>>>>>>>>>>>>>>>>>>>>>>>>

Enjoy reading our other articles and stay tuned with us.

Kindly do provide your feedback in the 'Comments' Section and share as much as possible.