BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
13 REPLIES 13
ChrisHemedinger
Community Manager
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
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
deleted_user
Not applicable
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?
ChrisHemedinger
Community Manager
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.
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
deleted_user
Not applicable
Hi,

Thanks! This version is working perfectly!

Your help on this issue is greatly appreciated.

Kind Regards
Willie
Mathan
Calcite | Level 5

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

   

ChrisHemedinger
Community Manager

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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Mathan
Calcite | Level 5

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?

ChrisHemedinger
Community Manager

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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Mathan
Calcite | Level 5

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

ChrisHemedinger
Community Manager

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;
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
the_allen_corp
Calcite | Level 5

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()

ChrisHemedinger
Community Manager

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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
deleted_user
Not applicable
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!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 13 replies
  • 6683 views
  • 0 likes
  • 4 in conversation