BookmarkSubscribeRSS Feed
Calcite | Level 5

I am trying to use visual c# to show the variable names of a sas dataset in a c# listbox. Sas EG is installed. I want to assign a libname for the location in the server of the data I choose from a openfiledialog but failed:

Libref libref = activeSession.Workspace.DataService.AssignLibref("amt", "", "\\\\sasserver\\public\\Temp\\", "");

BTW, I run "%sysfunc(pathname(work));" in sas eg, it print "D:\SASDATA\TEMP\user1\_TD**_**SAS9X64_\Prc2".

Anyone has some suggestions?


Community Manager

Does the same library assignment work within EG?  Example:

libname amt "\\sasserver\public\Temp\";

For the UNC (\\sasserver) notation to work on a remote Windows server and access another network resource (like a file share), the machine must be Trusted for Delegation.  See this topic in the SAS admin guide.

If you are looking to simply assign a library to a local folder on the Windows server, you can use the drive-letter notation.  Example:

libname amt "D:\public\Temp\";


activeSession.Workspace.DataService.AssignLibref("amt", "", "D:\\sasserver\\public\\Temp\\", "")

or using the @ symbol to avoid the double-slashes:

activeSession.Workspace.DataService.AssignLibref("amt", "", @"D:\public\Temp", "")


Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
Calcite | Level 5

It works with the libname statement in EG but failed using assignlibref in C# with error "User does not have appropriate authorization level for library". 

This link   this topic in the SAS admin guidecan not be opened.

I am trying to save the path to a variable after opening a dataset from the network drive(where sasserver is in) and then assign the libref to the path variable. Is there any function to map the UNC path to the local path in server?


Community Manager

Sorry about the bad link -- I've fixed it.  It's just the SAS topic on Trusted for Delegation setup, which sounds like it's not the issue you have unless you are using single-signon (integrated Windows authentication) in your C# program but not in your SAS EG session.  Or...unless you are authenticating using a different set of credentials in your C# program.

But...let me recap what I hear you saying:

- You have a C# app that displays a window to select a SAS data set.

- You display a Windows file dialog to select that file -- I assume this is navigating the file system from your local PC (not the SAS session file system)?

- You want to use that selection to "infer" a LIBNAME path that would work from a SAS session.

Is all of that correct?  If so, I think your approach can/should work -- but for some reason you're hitting a snag.  Without seeing more of the application code, it's difficult to diagnose.

The challenge is that what you might really want is a way to show the SAS server file system, but there isn't a SAS-provided method to show that structure.  You would have to use the Workspace FileServices APIs to find the different paths available in the SAS session, and then build your own UI to display/navigate those paths.


Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
Calcite | Level 5

I am using your sasHarness as a template for creating the sas.workspace. After connecting to the sas server, the api may not recognize the local UNC path "\\.." like sas EG does. Even using the LanguageService to submit ("libname amt \"\\\\S5280a08\\public\\Tmp\\\"; ") does not work. Really do not know how the EG handle this case.

Some error occurs while I am trying to parse the log using FlushLogLines instead of FlushLog. Still could not figure out how to fix the error.


An unhandled exception of type 'System.TypeLoadException' occurred in AMT.exe

Additional information: Could not load type 'SAS.LanguageServiceCarriageControl' from assembly 'AMT, Version=, Culture=neutral, PublicKeyToken=null'.


code segment:


            // test

            SAS.LanguageService lang = activeSession.Workspace.LanguageService;

            string[] sasPgmLines = {

"data _null_;",


"put a=;",



            //," proc print data=amt.a;",

            //" run;"  } ;

            System.Array linesVar = sasPgmLines; // identical to type of ref parm

            lang.SubmitLines(ref linesVar);

//FlushLog or FlushLogLines

// FlushLog works fine but FlushLogLines reports error

  //          label1.Text += lang.FlushLog(1000);

            bool bMore = true;

            while (bMore)


                System.Array CCs;

                const int maxLines = 100;

                System.Array lineTypes;

                System.Array logLines;

                lang.FlushLogLines(maxLines, out CCs,

                out lineTypes, out logLines);

                for (int i = 0; i < logLines.Length; i++)


                    label1.Text += (logLines.GetValue(i) + "\n");


                if (logLines.Length < maxLines)

                    bMore = false;



Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


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
  • 4 replies
  • 2 in conversation