Profile Change with code

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Profile Change with code

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.


Accepted Solutions
Solution
‎01-03-2017 09:15 AM
New Contributor
Posts: 3

Re: Profile Change with code

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.

View solution in original post


All Replies
Super User
Posts: 5,389

Re: Profile Change with code

Can you specify what kind of programming, or in what scenario would you like to be able to do this.
Since this a client GUI thing, you ate probably looking towards .Net. This not my field of experience, but the question is how/this should be triggered.
Data never sleeps
New Contributor
Posts: 3

Re: Profile Change with code

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.

Respected Advisor
Posts: 4,137

Re: Profile Change with code

[ Edited ]

@Mallen

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.

 

Capture.PNG

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. 

Super User
Posts: 3,238

Re: Profile Change with code

[ Edited ]

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.

Solution
‎01-03-2017 09:15 AM
New Contributor
Posts: 3

Re: Profile Change with code

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 380 views
  • 0 likes
  • 4 in conversation