The %WINDOW statement provides a facility to define a customized window that can be used to collect user input and display customized messages. It is controlled by a macro processor. SAS Enterprise Guide is a powerful Windows application that makes SAS programming much easier and organized. Since SAS Enterprise Guide works on a client/server model, it doesnt support the %WINDOW statement. PowerShell is a powerful automation tool, consisting of command-line shell and scripting language. Windows PowerShell supports GUI programming. On a few occasions, SAS programs need to perform tasks dynamically based on the inputs provided by the user. Since SAS Enterprise Guide doesnt support the %WINDOW statement, an alternate solution was needed to address this scenario. I came across two solutions: 1). Use Prompt Manager to create a prompt that can take user input, but the Prompt Manager is available only if you create a project. So, it doesnt meet the requirement. 2). Use PowerShell. It has the capability to design customized windows. So, PowerShell is selected to design the form. The task is to create XPT or Define XML based on information provided by the user. A PowerShell script is written to take user input and save the input taken to a text file. SAS programs can utilize the text file to read and produce the appropriate result. A single PowerShell script can be written to take user input and run SAS programs. This presentation will explain the entire process using screenshots and PowerShell code.
Watch Alternate Solution to %WINDOW statement in SAS® Enterprise Guide®: PowerShell as presented by the author on the SAS Users YouTube channel.
%WINDOW statement provides the facility to define a customized window that can be used to collect user input and display customized messages. It is controlled by macro processor. SAS® Enterprise Guide® is a powerful windows application making SAS programming much easier and organized. Since SAS® Enterprise Guide® works on client/server model, it doesn’t support %WINDOW statement. PowerShell is a powerful automation tool, consisting of command-line shell and scripting language. Windows PowerShell supports GUI programming.
On few occasions, SAS program needs to perform task dynamically based on the inputs provided by user. Since SAS® Enterprise Guide® doesn’t support %WINDOW statement, an alternate solution was needed to encounter this scenario. I work in Citrix environment that provides Windows Server 2012 R2 and had constraint to take user input either using SAS programming (through SAS® Enterprise Guide®) or some open source language/software that doesn’t need installation by IT department. I came across two solutions:
I have selected PowerShell to design form. Let’s understand with the help of an example. Task is to create XPT or Define XML based on information provided by user. User defined SAS macro is written for XPT creation or Define XML generation. It needs the following three inputs from user:
PowerShell script is written to take user input and save the input taken to a text file. The screen below was created using PowerShell. See Figure 1
Program is mentioned in the Appendix (Screen.ps1)
Figure 1. User Input Form
User needs to select option from drop-down box. The screenshot below shows the options selected by user. See Figure 2
Figure 2. Options selected by User
Now SAS program can utilize the text file to read and produce the appropriate result i.e. either create XPT or generate Define for selected module and selected study.
Consider SAS program is ready to read text file and run the user defined SAS macro for XPT creation or Define generation. Running the SAS program could be done in two ways:
In this paper, only one aspect of PowerShell has been discussed although PowerShell is very powerful automation tool that can be utilized for various purposes. Combining SAS with PowerShell gives more flexibility to programmers to automate tasks.
https://docs.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.1
Your comments and questions are valued and encouraged. Contact the author at:
Sumit Pratap Pradhan
Syneos Health, Principal Statistical Programmer
Building No. 14, Tower B, DLF Cyber City, Gurgaon - 122002, Haryana, India
E-mail: sumit.pradhan@syneoshealth.com
LinkedIn: https://www.linkedin.com/in/sumit-pradhan-71133345/
Any brand and product names are trademarks of their respective companies.
<# ****** POWERSHELL SCRIPT *******
*********** SCREEN.PS1 ************
******************************** #>
#Load Required assemblies for Form Creation
Add-type -AssemblyName System.Windows.Forms
#Design User Input Form
$Form_Input = New-Object System.Windows.Forms.Form
$Form_Input.Text='User Input'
$Form_Input.width = 400
$Form_Input.height = 300
#Add Group
$Group_Input = New-Object System.Windows.Forms.GroupBox
$Group_Input.Location=New-Object System.Drawing.Size(40,30)
$Group_Input.Size=New-Object System.Drawing.Size(300,160)
$Group_Input.Text='Select options from below'
#Add Drop-Down Button having Task details
$Button_Task = New-Object System.Windows.Forms.ComboBox
$Button_Task.Location=New-Object System.Drawing.Size(20,40)
$Button_Task.Name='Button_Task'
$Button_Task.Size=New-Object System.Drawing.Size(150,20)
$Button_Task.Text='Select Task'
#Add to Group
$Group_Input.Controls.Add($Button_Task)
#Add Drop-Down for Module
$Button_Module = New-Object System.Windows.Forms.ComboBox
$Button_Module.Location=New-Object System.Drawing.Size(20,70)
$Button_Module.Name='Button_Module'
$Button_Module.Size=New-Object System.Drawing.Size(150,20)
$Button_Module.Text='Select Module'
#Add to group
$Group_Input.Controls.Add($Button_Module)
#Add Drop-Down for Study
$Button_Study = New-Object System.Windows.Forms.ComboBox
$Button_Study.Location=New-Object System.Drawing.Size(20,100)
$Button_Study.Name='Button_Study'
$Button_Study.Size=New-Object System.Drawing.Size(150,20)
$Button_Study.Text='Select Study'
#Add to group
$Group_Input.Controls.Add($Button_Study)
# TASK VALUES
$Button_Task.Items.Clear()
ForEach ($Itemt in 'XPT Creation', 'Define Generation') {
$Button_Task.Items.Add($Itemt)
}
# MODULE VALUES
$Button_Module.Items.Clear()
ForEach ($Itemm in 'SDTM', 'ADaM') {
$Button_Module.Items.Add($Itemm)
}
# STUDY VALUES
$ROOTPATH='C:\Users\supradha\Desktop\SAS';
$areaval = (Get-ChildItem -Path $ROOTPATH -Directory -Exclude root).Name
$Button_Study.Items.Clear();
ForEach ($Itemts in $areaval) {
$Button_Study.Items.Add($Itemts)
}
#Add Submit Button
$Button_Submit = New-Object System.Windows.Forms.Button
$Button_Submit = New-Object System.Windows.Forms.Button
$Button_Submit.Location=New-Object System.Drawing.Size(150,200)
$Button_Submit.Size=New-Object System.Drawing.Size(100,40)
$Button_Submit.Text='Submit'
$Button_Submit.DialogResult=[System.Windows.Forms.DialogResult]::abort
#Add Submit Button to Form
$Form_Input.Controls.Add($Button_Submit)
#Add Group to Form
$Form_Input.Controls.Add($Group_Input)
$Form_Input.CancelButton = $Button_Submit
$Form_Input.Add_Shown({$Form_Input.Activate()})
$Form_Input.showdialog()
#Create TEXT file to store selected option
"TASK: "+ $Button_Task.text +
"`r`nMODULE: "+ $Button_Module.text +
"`r`nSTUDY: "+ $Button_Study.text +
''| Out-File "$ROOTPATH\User_input.txt" -Force
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Select SAS Training centers are offering in-person courses. View upcoming courses for: