Desktop productivity for business analysts and programmers

SAS Enterprise Guide Automation using C#

Reply
N/A
Posts: 0

SAS Enterprise Guide Automation using C#

Hi,

I came accross the following document on how to perform some Enterprise Guide automation a while ago. I currently have some projects where I need to do this sort of thing and I was very delighted when I came accross this document as this is exactly what I need to complete my projects.

http://www2.sas.com/proceedings/forum2007/016-2007.pdf

However, once I implemented these code snippets into C# to test and play with them, I came accross the following error message once I tried to run the code:

System.IO.FileNotFoundException: Could not load file or assembly 'SAS.OCT.OlapClientEngine, Version1.3.0.0, Culture=neutral, PublicKeyToken=be58efc3b934219b' or one of itsdependencies. The system cannot find the file specified. File name: 'SAS.OCT.OlapClientEngine, Version1.3.0.0, Culture=neutral, PublicKeyToken=be58efc3b934219b'
at SAS.EG.ProjectElements.ProjectCollection.SetDataModelOptions()
at SAS.EG.ProjectElements.ProjectCollection.set_AppOptions(EGOptions value)
at SAS.EG.Scripting.Application..ctor()

I am currently running EG 4.1 and code using Visual Studio 2005.

Your help with this matter would be greatly appreciated!

Regards
Community Manager
Posts: 2,884

Re: SAS Enterprise Guide Automation using C#

Willie,

When Kevin was preparing that paper, I helped by providing a helper C# class that would resolve assembly loading issues like this.

Here's a version that can help work for EG 4.1. It's attached to this message (I think, as long as I've got attachments working...)

Instructions:

1. Add the attached class to your project. Change namespace as necessary.

2. Put SEG4AssemblyResolver.Install() in your Main(). Like this:

[pre]
[STAThread]
static void Main()
{
SEG4AssemblyResolver.Install();
System.Windows.Forms.Application.Run(new Form1());
}
[/pre]

Then set Copy Local to False for your EG assembly references. The app should run standalone on a machine where EG 4.1 is installed, from any directory.

Chris
N/A
Posts: 0

Re: SAS Enterprise Guide Automation using C#

Hi,

Thanks for the attachment. It will cerainly help.

However, I have included this into my program and it still gives me an error message. From the message I gathered that it is looking for a dll file called "SAS.OCT.OlapClientEngine.dll". I do not have this file in my SAS/Enterprise Guide folder. Is this perhaps something that needs to be installed additionally?
Community Manager
Posts: 2,884

Re: SAS Enterprise Guide Automation using C#

Here's a fancier version (attached to this message) that should cover that.

1. Add the CS file to your project.

2. In your Main() function (before the Run(Form) line), call:

SEG4Automation.SEG4AssemblyResolver.Install();

3. Change your reference settings so that Copy Local is set to false:
- right-click on SASEGScripting in your References section->Properties
- set Copy Local to "False"

After rebuilding, you should be able to drop your EXE on any machine with EG 4 installed, in any directory, and have it work.
N/A
Posts: 0

Re: SAS Enterprise Guide Automation using C#

Hi,

Thanks! This version is working perfectly!

Your help on this issue is greatly appreciated.

Kind Regards
Willie
Occasional Contributor
Posts: 7

Re: SAS Enterprise Guide Automation using C#

hi,

    I'm fully new to SAS, trying to automate like this, but i'm not able to download SEG4AssemblyResolver.c s (2.9 K) file can u help please. Getting "Error An general error occurred while processing your request."

   

Community Manager
Posts: 2,884

Re: SAS Enterprise Guide Automation using C#

I have a couple of .NET automation examples out on the support site.  These are meant for EG 4.2 and Visual Studio 2008, but I'll be creating new ones soon in preparation for SAS Global Forum presentation.

Here's a version for C#.

Here's a version for VB.NET.

Chris

Occasional Contributor
Posts: 7

Re: SAS Enterprise Guide Automation using C#

Hi Chris@SAS,

     Happy thanks for ur reply and help. Its Working fine.

I have one more doubt!!! Is it possible to find the Variable format datatype name like 'Date','DateTime','Time',etc... in SAS7bdat extension files?

Community Manager
Posts: 2,884

Re: SAS Enterprise Guide Automation using C#

Mathan,

Apologies for the delayed reply.

The logic to determine the "type" is done by classifying the format of the variable.  As you might know, SAS variables are one of two types: numeric or character.  Depending on the SAS format applied to a numeric variable, we can guess its probable role.  For example, a numeric variable with MMDDYY6. format is a Date value.

We have some helper classes in the SAS.Tasks.Toolkit assembly that provide this logic for use in custom tasks, but I'm not aware of any "loose" C# code lying around that does the work.

Chris

Occasional Contributor
Posts: 7

Re: SAS Enterprise Guide Automation using C#

Hi Chris,

          Thanks for your reply... I need one more help!!!

After long R&D I got the required output by the following code.

CODE :

ods xml file="C:\Users\sas\Desktop\text2.xml";

  proc contents data='C:\\Users\\sas\\Desktop\\SAS\\cal_sample.sas7bdat' out=contents DETAILS;

  run;

ods _all_ close;

In this 'cal_sample.sas7bdat' file its variable name length is of max 8 characters only, so i got the expected test2.XML as output and i proceessed it to get my output.

But for some sas7bdat files which consists of more than 8 characters as its variable name, in this case alone i'm not getting the XML that is required.

Can u help with any other code that can help me with dis pls..

Community Manager
Posts: 2,884

Re: SAS Enterprise Guide Automation using C#

Instead of using PROC CONTENTS, you can try something like this:

libname data "C:\Users\sas\Desktop\SAS";
/* table level data */
PROC SQL;
   SELECT t1.memname, 
          t1.nobs FORMAT=comma15., 
          t1.filesize FORMAT=comma20., 
          t1.nvar, 
          t1.num_character, 
          t1.num_numeric
      FROM SASHELP.VTABLE t1
      WHERE t1.libname = 'DATA';
QUIT;

/* report on columns in each table */
PROC SQL;
   SELECT t1.memname, 
          t1.name, t1.type, t1.format, t1.informat
      FROM SASHELP.VCOLUMN t1
      WHERE t1.libname = 'DATA' and t1.memtype='DATA';
QUIT;
N/A
Posts: 1

Re: SAS Enterprise Guide Automation using C#

I am having the same issue with SAS 4.3, see below: Will you process handle that, if so I may need a little help setting it correctly.

ERROR: SAS Process Failed with below exception:

System.TypeInitializationException: The type initializer for 'SAS.EG.Scripting.Application' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=be58efc3b934219b' or one of its dependencies. The system cannot find the file specified.

File name: 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=be58efc3b934219b'

   at SAS.EG.Scripting.Application..cctor()

Community Manager
Posts: 2,884

SAS Enterprise Guide Automation using C#

Yes, you need to use the AssemblyResolver approach that I posted about earlier.

I'm presenting this as part of an larger automation topic at SAS Global Forum this year.  I will have a more complete code example available very soon.

Chris

N/A
Posts: 0

Re: SAS Enterprise Guide Automation using C#

All,

I've been trying to use the SASEGScripting library in order to accomplish the things outlined in the original poster's PDF link. I've been able to do the following in C#:

1. The constructor of my class can open an application instance of EG.
2. It can then open an existing EG project.
3. It can utilize a given EG profile that I have loaded on the client machine.
4. It can also access the code collection of this project. I'm able to display the project's code.

I then try to use the Run() function for my ISASEGCode instance, and then place its results into ISASEGResults. I then want to use the SaveAs function from the ISASEGResults class to save the resulting output dataset to a certain path.

The issue is, in spite of the application, remote server connection, project, and code pieces seemingly working, no results get created, causing my SaveAs call to complain about an index out of range.

The project I'm using to test this works in the EG GUI, it's simply extracting the first 100 observations from a table on a remote server and outputting it to the default WORK library.

Are there any good guides that discuss how to use SASEGScripting? Has anyone been able to successfully open an EGP, run the code, and save the output locally using C#?

Any help would be greatly appreciated!
Ask a Question
Discussion stats
  • 13 replies
  • 2836 views
  • 0 likes
  • 4 in conversation