BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mallen
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Mallen
Fluorite | Level 6

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

5 REPLIES 5
LinusH
Tourmaline | Level 20
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
Mallen
Fluorite | Level 6

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.

Patrick
Opal | Level 21

@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. 

SASKiwi
PROC Star

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.

Mallen
Fluorite | Level 6

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 3613 views
  • 1 like
  • 4 in conversation