Monday, December 30, 2013

SAS and Bing Maps API

Here is a method for using SAS and Bing Maps:

  1. Signed up for a key on Bing Maps API. Create a basic key and copy it somewhere. I will demonstrate it in the SAS code as [BINGKEY] since I cannot share mine publicly: https://www.bingmapsportal.com/

  2. Use the following code:
  3. %let z1=47.64054;
    %let z2=-122.12934;
    %let BINGKEY=%NRSTR(&key=[BINGKEY]);

    filename x url "http://dev.virtualearth.net/REST/v1/Locations/&z1.,&z2.?o=xml&BINGKEY";
    filename z "c:\temp\BingMap.xml";

    data _null_;
    infile x ;
    file z ;
    input;
    put _INFILE_;
    run;

  4. Parse the xml that is produced as needed. You can also output it as JSON if you change the word xml in the URL to json.

Monday, November 18, 2013

SAS EG Add-Ins and WPF

Well, I finally made progress on getting my dynamic WPF add-in working. This was in large part to Chris Hemedinger helping out with some questions. What I have learned, I want to share so it is not lost.

WPF works fine with EG except for some graphics issues found when the form is displayed in EG. Not a major issue, a minor one.

The main thing is that it works, runs dynamically using web services on the backend, uses MEF (very cool Framework), and saves us a lot of effort.

Here are some of Chris' suggestions.

How to debug

 
To be effective at debugging, you need a professional version of Visual Studio.  The Express editions don't allow you to debug an application unless you built that app (the EXE) with Express.  

 

Assuming that you have the a Pro version, you can use this approach:

-          Copy the DLL and PDB (symbols) file into the directory where you are putting Custom tasks.

-          Start EG as normal, see the custom task in the Add-Ins menu.

-          Before you launch the task, use Visual Studio to attach to the process.  With your add-ins project loaded, select Debug->Attach to Process.  Find SEGuide.exe and attach.

-          Set breakpoints in your add-ins code as needed.  You can also select Debug->Exceptions, check "Break when exception is thrown" for managed code.

 

I don't recommend throwing exceptions from your task unless you also have other code that will catch the exception.  If you allow an exception to bubble up to the SEGuide.exe app, it won't be good for your end user.  Potentially work will be lost in the project.  It's best to catch the exceptions that you can control/react to, and contain them in your add-in.

Adding Nodes Programmatically



To prevent the task from appearing in the process flow, implement it as a modeless window and return ShowResult.Cancel immediately after your task window is displayed.  I think the catalog explorer example does this, as does the SAS Macro Viewer example.  You will have to add logic to guard against project changes (while your task is running) and re-entrant logic (prevent more than one instance of your task per session).  

 

Now, to add a program node to the project – that's trickier.  If you create a program file (.SAS file on disk), you can trick EG into opening it in the current session.  See the "Program Manager (C#)" example that you can find here:

 


 

Beyond that, there is not a supported method for creating a new program node (or any node) programmatically via the task APIs.

 

Monday, October 28, 2013

SAS EG "add-in is an invalid file type"

I am working on a SAS EG Add-In right now. As part of it, I encountered this error:

"add-in is an invalid file type"

Ok. Great. How do I solve it?

For my project, it turned into a missing dll. Simple? Yes, but it took hours to track down. Hopefully this post helps out the next person.

Chris H. suggested the following means of finding the cause of an error:



You can "debug" the issue with the logging.config approach, which I show in the custom tasks book.  The generated log file will show the DLLs that are loaded and provide more details about problems encountered.

To turn on logging:


Thanks Chris.

Thursday, March 14, 2013

SOAP Error on Encoding

If you are trying to get a web service operational and encounter errors similar to the following:


SOAPUI error:

The message could not be processed. This is most likely because the action 'http://tempuri.org/ISas9Users/GetSasUsers' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.

SAS error:

ERROR: org.springframework.ws.client.WebServiceTransportException: Cannot process the message because the content type 'text/xml;

charset=UTF-8' was not the expected type 'application/soap+xml; charset=utf-8'. [415]

WCF Error: The caller was not authenticated by the service.
 
 
Make sure you use basicHttpBinding vs wsHttpBinding in your web.config if using WCF (which I am). 
 
 
Also, you may need to check your XML and make sure you have the encoding defined in the XML header:
 
 

Tuesday, February 26, 2013

SAS Deployment Manager and Meadow Muffins

Ok, so I am deep in the depths of the SAS Deployment Manager and am learning things the hard way (and spending time curled into a fetal position).

Ok, let's start with uninstall because it is this morning's pain point.

When creating a quiet uninstall, here is the command I was using:

"C:\Program Files\SAS 9.3.0 (SAS BI Solutions)\SASDeploymentManager\9.3\sasdm.exe" -uninstall -record -responsefile "c:\temp\uninstall2.txt"

I have highlighted in yellow my mistake. By including the -uninstall, the resulting responsefile was missing a critical component:

 MANAGE_TASK=uninstall

Why SAS does not ignore it, I am unsure of. How do you know it fails? Well, you don't easily. It seems to run, then just goes back to a command prompt. The sas.mif file will show a failure if you go and look at it:

cd %TEMP%
type sas.mif

Watch this issue on the install as well. Per the SAS documentation:

If you use any other command line options while using record, those options are not included in the response file. To properly use the response file, you must repeat those same command line options with the playback.


  Huh? Why would you leave out critical features on a quiet install/uninstall?   The next joy here is the little meadow muffins SAS leaves everywhere. You still have a Program Files entry, registry remnants, Start Menu leftover, etc.   To be honest, the process is getting WAY, WAY easier and the above issues are mostly documented. However, here are some suggestions for the future:  

  • Allow a command line option that will remove EVERYTHING. Don't make me code against the registry and muck with the Start Menu. As it stands, i will have to have a script do this which should be unnecessary.
  • Do not accept extraneous commands on the record part of the responsefile. Flag them or ignore them
  • Do not care about the order of the command options. (see below)
  • Offer a utility that can help create the responsefile rather than doing it all command line. If one is out there, i am unaware of it.
  • Retrofit the hotfix issues into 9.3M1. Some commands like silenthotfix are only available in 9.3M2 and there is no reason they should not be available for 9.3M1 that I can think of.

Proper Steps to Do Install (make sure you have the correct order)

Create a response file:

"C:\Program Files\SAS 9.3.0 (SAS BI Solutions)\SASDeploymentManager\9.3\sasdm.exe" -record -responsefile "c:\temp\install.txt"


Execute it:

c:\Packages\SAS93Depot\setup.exe -wait -quiet -responsefile "C:\temp\install.txt" -loglevel 2

Proper Steps to Do Uninstall


Create a response file:

"C:\Program Files\SAS 9.3.0 (SAS BI Solutions)\SASDeploymentManager\9.3\sasdm.exe" -record -responsefile "c:\temp\uninstall.txt"

Execute the response file:

"C:\Program Files\SAS 9.3.0 (SAS BI Solutions)\SASDeploymentManager\9.3\sasdm.exe" -wait -quiet -responsefile "C:\temp\uninstall.txt"

[UPDATE: 02/26/2013 7:06PM MST]

- Order of parms does not seem to matter. I am crashing on the SAS install due to the threading within my own application. Where the bug lies? I do not know but it is not pertinent to this topic.

- I had to go and back out some values from the registry. I must have deleted over 50 keys. I am unsure why so many keys are needed. This is something that I think SAS could improve upon.

SAS throwing RPC error

If you are doing code in C#  and get this error when creating a LanguageService: The RPC server is unavailable. (Exception from HRESULT:...