You can use PowerShell Variables with the Cmdlets4Sas.
This enables you to automate your workflow. All the control logic is handled in powershell.
In this sample we will cover the following steps:
# ensure module is loaded
if(!(Get-Module Cmdlets4Sas))
{Import-Module Cmdlets4Sas}
# Connect to server
$ws = Connect-SasWorkspaceLocal
# define macro
$code = @"
%macro hello(name);
%put Hello &name!;
%mend hello;
"@
# submit code
Invoke-SasCode $ws $code
# create an powershell array with some data
# you may also import data from e.g. a local CSV file with the Import-Csv Cmdlet
$names = @("alice",
"alfred",
"barbara",
"bob",
"carol",
"$env:USERNAME" # use powershell variable with your username
)
# submit SAS code for each item in the array
foreach ($name in $names)
{
if ($name -ne "bob") # check if name is not equal to "bob"
{
# use powershell variable $name in SAS code
Invoke-SasCode $ws "%hello($name);"
}
}
# write the SAS log to the console
Read-SasLog $ws
Disconnect-SasServer $ws