BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi guys, Chris,
I am new to both SAS and Visual Studio. For the last couple of weeks I have learned to write a SAS macro for my financial auditing job. My boss wants me to develop a custom task for SAS EG using VB. We now have Visual Studio 2005 pro. I spend a few days searching the web and trying to understand the codes of some sample custom tasks on the web but only got a very rough picture. Some points still confused me, for example

How to call a SAS macro with parameters in VB ?(although I have seen an equivalent C# code from one of the sample custom tasks downloaded from SAS support page)

How to create the .dll file? etc.

Any suggestions, pointer or examples on this? Much appreciated.
12 REPLIES 12
ChrisHemedinger
Community Manager
John,

Most custom tasks simply generate SAS code based on user selections in one or more forms presented in the task. When you already have a SAS macro that does the work you want, the only variation in the generated code from run to run is the parameters passed to the macro, or else perhaps some %LET statements to set up some variables.

You're not calling the macro directly from the task; you are simply generating a SAS program that will call the macro when run within EG.

Is there a C# example that we have that looks like what you want to do? If so, post back and I'll try to provide some code snippets for a VB.NET equivalent.

One other note: if you are using VS2005, you'll want to look at this thread:
http://support.sas.com/forums/thread.jspa?forumID=10&threadID=121&tstart=0

Chris
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
deleted_user
Not applicable
Thanks Chris,

It helps me clarify things a little bit. And here is the C# code of a sample custom task from http://support.sas.com/documentation/onlinedoc/guide/release30/addins/

public string SasCode
{
get
{
string member = (bAllMembers || dataset.Length==0) ? "_ALL_" : dataset;
string co = catobs.ToString();
string macro = Global.ReadFileFromAssembly("EGAddin.CharacterizeData.Characterize_Data.sas");
string call = string.Format("%charact(dsn={0},lib={1},catobs={2});",member,library, co);
string charts = (bCharts) ? Global.ReadFileFromAssembly("EGAddin.CharacterizeData.GraphCode.sas") : "";

string code = macro + Environment.NewLine + call + Environment.NewLine + charts;

return code;
}
}

I guess most of my questions are really from VB side. Any resources of VB programming for a beginner you would share? Thanks a lot!
ChrisHemedinger
Community Manager
Here is the VB.NET version of this function:

Public Function get_SasCode() As String
Dim member As String = IIf((Me.bAllMembers OrElse (Me.dataset.Length = 0)), "_ALL_", Me.dataset)
Dim co As String = Me.catobs.ToString
Dim macro As String = Global.ReadFileFromAssembly("EGAddin.CharacterizeData.Characterize_Data.sas")
Dim call As String = String.Format("%charact(dsn={0},lib={1},catobs={2});", member, Me.library, co)
Dim charts As String = IIf(Me.bCharts, Global.ReadFileFromAssembly("EGAddin.CharacterizeData.GraphCode.sas"), "")
Return macro & Environment.NewLine & call & Environment.NewLine & charts
End Function


Great places to start with .NET development:
http://www.gotdotnet.com (Microsoft-supported community)
http://www.codeproject.com

Chris
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
deleted_user
Not applicable
Thanks a million Chris!
deleted_user
Not applicable
Hi Chris,
I have another question, under ISASTaskDescription, where does the Clsid come from, here's the example from the SAS custom task page,

Public ReadOnly Property Clsid() As String Implements SAS.EG.AddIns.ISASTaskDescription.Clsid
Get
Clsid = "7c02a543-9187-40ef-a835-b59420ce6fb9"
End Get
End Property


Thanks,
John
ChrisHemedinger
Community Manager
John,

The Clsid property returns a value called a GUID, which you can generate easily from a Visual Studio command prompt. Simply run "uuidgen", and it will generate one for you -- copy and paste it into your task code.

The Visual Studio templates that we provide (for VS2003) will generate the value for you. If you are developing a task without using the templates, you'll have to use uuidgen.

It's important to supply a unique value for the Clsid for each task. This value is how Enterprise Guide can distinguish one task from another. If you have two or more tasks with the same Clsid value in your \Custom directory, Enterprise Guide will show only the first one it finds.

Chris
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
deleted_user
Not applicable
Thanks again Chris!

Where do I copy the number generated by uuidgen.exe into? Clsid property or Assembly > UGID?

And why do I keep getting such addin manager error message "the add-in does not contain the correct interface signature"? Is that because I am using Visual Studio 2005?

Since I can't use the VS 2003 template, can you please confirm this:

All I need is an user interface Window form.vb and a classlibrary.vb implementing SASTask subs. All the other .vb like Assembly.vb will be generated by VS?

Cheers,
John
Message was edited by: John_learntoSAS at Jun 1, 2006 1:35 PM
ChrisHemedinger
Community Manager
John,

Yes, copy the GUID to the Clsid property implementation.

And yes, since you don't have the benefit of the templates, you need to implement ISASTask, ISASTaskAddIn, and ISASTaskDescription yourself. All of that is very easy with Visual Studio.

See my previous posting re: using VS2005. You cannot create custom tasks that use .NET 2.0 (EG 4.1 won't support that), so you'll need to target .NET 1.1 with VS2005. That's possible to do with an extension called MSBee available from Microsoft.

Chris
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
deleted_user
Not applicable
Thanks Chris, you are such a great help!
deleted_user
Not applicable
Thanks again Chris, I finished my little custom task and my boss was happy. One question though is how do I code the SAVE function (so I can save the process and schedule it just like the other tasks do)?


cheers,
John
deleted_user
Not applicable
Hi Chris,

The same question again. How do I code the SAVE function (so that the process is saved as a schedule task)? Much appreciated!

cheers,
John
prholland
Fluorite | Level 6
John,

You'll need to code a replacement Public Property for XmlState (in ISASTask), which reads and writes the state of the task in XML format. An example can be found in the following code (from ClassicHat.vb):

Public Property XmlState() As String Implements _
SAS.Shared.AddIns.ISASTask.XmlState
Get
Dim sw As StringWriter = New StringWriter
Dim writer As XmlTextWriter = New XmlTextWriter(sw)
writer.WriteStartElement("ClassicHat")
writer.WriteElementString("Size", _
XmlConvert.ToString(HatSize))
writer.WriteEndElement()
writer.Close()
XmlState = sw.ToString()
End Get
Set(ByVal Value As String)
If Value <> Nothing And Value.Length > 0 Then
Try
Dim sr As StringReader = New StringReader(Value)
Dim reader As XmlTextReader = New XmlTextReader(sr)
reader.ReadStartElement("ClassicHat")
HatSize = _
XmlConvert.ToInt32(reader.ReadElementString("Size"))
reader.ReadEndElement()
reader.Close()
Catch
End Try
End If
End Set
End Property

.............Phil

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 12 replies
  • 1807 views
  • 0 likes
  • 3 in conversation