When you open SAS Enterprise Guide you have the last profile already selected. You can change by click the profile and choosing another to Set Active. How do you do the same thing using code within a SAS project.
The problem is we run our SAS code from Task scheduler using the built-in VBS (vbscript); other users get on the remote automation system and switch profiles. So when my schedule runs it has the wrong profile and doesn't run, it just sits at a pronmpt for credentials.
I found a solution though, good info if others need to switch profile prior to running SAS through automation. You just need to run a script or .bat file, to replace the config file (its an XML file). Just create a copy of the current config XML, and there is a line in the file that says which profile is set to active; in your copy just put the profile you want as Active, other than that line the file should stay the same. Then have your script/.bat file replace that file, prior to running your SAS code. If someone changes profile manually later, your automation will cahnge it back prior to your SAS running. I am using this process now, and it works perfect.
- Line in XML file:
<Settings>
<ActiveProfile>Profile 1</ActiveProfile>
<GenerateLocalServer>True</GenerateLocalServer>
</Settings>
</Configuration>
- Line in your XML:
<Settings>
<ActiveProfile>Profile 2</ActiveProfile>
<GenerateLocalServer>True</GenerateLocalServer>
</Settings>
</Configuration>
- Location of config file (in Windows): C:\Users\%username%\AppData\Roaming\SAS\MetadataServerProfiles
- XML file original: ConfigurationV71.xml
- XML your copy (you can name whatever): ConfigurationV71_Profile2.xml
- Script/.Bat: Copy C:\Users\%username%\AppData\Roaming\SAS\MetadataServerProfiles\ConfigurationV71_Profile2.xml C:\Users\%username%\AppData\Roaming\SAS\MetadataServerProfiles\ConfigurationV71.xml /y
- Additional Info: All profile names are listed in this XML file, in the Profiles section (<<Profile1>>, etc...), so just find the one you need and put in the active line.
I want to do it inside SAS program. It opens, then before it does any libnames or includes, I want it to check which profile is being used and change if necessary.
SAS EG is the client connecting to a SAS server. The SAS EG profile provides the connection info to the SAS Metadata server. Before you can execute any SAS code you first need to establish a connection to the SAS Server (Metadata Server and then Workspace Server). That's why you can't execute SAS code to do this for you.The SAS EG profile resides on the client side within EG. Code run on the SAS Server side can't modify your client side EG profile.
http://support.sas.com/resources/papers/proceedings13/420-2013.pdf
The full info of how this works here (i.e. chapter 10):
http://support.sas.com/documentation/cdl/en/bisecag/69827/PDF/default/bisecag.pdf
Once connected to a SAS Metadata Server you might get access to one or multiple SAS Application Servers ("Workspace Server") - that's what you then see in EG under "Servers". You run your SAS code against one of these Application Servers. Only when you connect to an Application Server SAS code will get executed and for each application server a new SAS Workspace will get initiated. It's during this initiation phase that libraries get assigened via SAS Metadata definitions for your Metadata user and this is specific to the Application Server plus whatever is defined in this Application Servers config and autoexec files.
In an EG project under Tools/Options/SAS Programs you can define code to be executed when connecting to a Server "Submit SAS code when server is connected". You could there define some code which does different things depending on which SAS Application Server you connect to - so not SAS EG profile specific but SAS App Server specific.
You would have to write a SAS macro for this and you could use the Global SAS macro variable &_SASSERVERNAME. Issue a "%put _global_;" statement in EG to see what macro variables are available to you.
What is your business requirement for wanting to switch EG profiles? If you can state what that is we could possibly find an alternative approach to satisfy it.
The problem is we run our SAS code from Task scheduler using the built-in VBS (vbscript); other users get on the remote automation system and switch profiles. So when my schedule runs it has the wrong profile and doesn't run, it just sits at a pronmpt for credentials.
I found a solution though, good info if others need to switch profile prior to running SAS through automation. You just need to run a script or .bat file, to replace the config file (its an XML file). Just create a copy of the current config XML, and there is a line in the file that says which profile is set to active; in your copy just put the profile you want as Active, other than that line the file should stay the same. Then have your script/.bat file replace that file, prior to running your SAS code. If someone changes profile manually later, your automation will cahnge it back prior to your SAS running. I am using this process now, and it works perfect.
- Line in XML file:
<Settings>
<ActiveProfile>Profile 1</ActiveProfile>
<GenerateLocalServer>True</GenerateLocalServer>
</Settings>
</Configuration>
- Line in your XML:
<Settings>
<ActiveProfile>Profile 2</ActiveProfile>
<GenerateLocalServer>True</GenerateLocalServer>
</Settings>
</Configuration>
- Location of config file (in Windows): C:\Users\%username%\AppData\Roaming\SAS\MetadataServerProfiles
- XML file original: ConfigurationV71.xml
- XML your copy (you can name whatever): ConfigurationV71_Profile2.xml
- Script/.Bat: Copy C:\Users\%username%\AppData\Roaming\SAS\MetadataServerProfiles\ConfigurationV71_Profile2.xml C:\Users\%username%\AppData\Roaming\SAS\MetadataServerProfiles\ConfigurationV71.xml /y
- Additional Info: All profile names are listed in this XML file, in the Profiles section (<<Profile1>>, etc...), so just find the one you need and put in the active line.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.