- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Chris,
I am trying to study and use your SAS Harness, but find out that the SAS workspace server only allow me to connect through SAS EG. When I try to connect to workspace server using SAS Harness, it give me error mesage saying I don't have permission. My question is can I use COM protocol to connect to our SAS Unix server instead of workspace server (that is set on a different unix node). If it can be done, do you have an example? This is more useful, because all our data and programs are on this SAS unix server.
Thanks!
Yihong
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yihong, sorry for the delay on this. Here's a C# example of copying a file from "SASApp" to the local PC. This example has several hardcoded values, so you'll need to adapt for your own situation.
using SAS.Tasks.Toolkit;
/* ... */
// initialize the path of the source file on the SAS server
// ex: '/u/myid/data/test.csv'
string filename = txtFile.Text;
// assuming filename ends with extension
// results in 'csv', for example
string ext = filename.Split('.')[filename.Split('.').Length - 1];
// get an object that represents the SAS server session
SasServer s = new SasServer("SASApp");
// copies to a local TEMP folder, returns the full path where
// it was copied to
string dest = s.CopyServerFileToLocal(filename, "test", ext);
MessageBox.Show("Copied file to " + dest);
You'll see a message like:
Copied file to C:\Users\sascrh\AppData\Local\Temp\SEG1896\ekecsy3k.2hj\test.csv
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Through Object Broswer, I saw the following. They all need a local SAS server, right? So for SAS EG that has no local server, they cannot be used?
SAS.Tasks.Toolkit.SasServer.CopyLocalFileToServer(string)
SAS.Tasks.Toolkit.SasServer.CopyServerFileToLocal(string, string, string)
SAS.Tasks.Toolkit.SasServer.CopyServerFileToLocal(string, string)
Or ask the question in a different way. do you have examples to do the following for SAS EG on Unix server without local server:
1. Transfer a local text file to Unix.
2. Transfer a unix text file to Local.
3. Transfer a SAS dataset from Unix to Local.
4. Transfer a SAS dataset from Local to Unix.
These will be very helpful for me to start.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yihong,
In this case, the "Local" in these method names is "local PC" -- no Local SAS is required. I'll try to come up with a simple example that you can use.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That will be great!
Thanks!
Yihong
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Chris,
While waiting for the file and data transfer examples, I have another question.
In the following is the code in your book page 64. I get erroes as shoown in the mouse on message shown.
I do have SAS.Tasks.Toolkit reference added and have using SAS.Tasks.Toolkit; and using SAS.Tasks.Toolkit.Data; on top of my program. Anything elsse I am missing?
Also, in the TopN example, I can not find this piece of code to see how it is used. Where can I find it in the TopN example?
Thakns!
Yihong
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yihong,
Add these using directives to the top of your file:
using System.Collections.ObjectModel;
using System.Collections.Generic;
You can always right-click on the "offending" keyword and select Resolve to see if Visual Studio has any suggestions for you.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yihong, sorry for the delay on this. Here's a C# example of copying a file from "SASApp" to the local PC. This example has several hardcoded values, so you'll need to adapt for your own situation.
using SAS.Tasks.Toolkit;
/* ... */
// initialize the path of the source file on the SAS server
// ex: '/u/myid/data/test.csv'
string filename = txtFile.Text;
// assuming filename ends with extension
// results in 'csv', for example
string ext = filename.Split('.')[filename.Split('.').Length - 1];
// get an object that represents the SAS server session
SasServer s = new SasServer("SASApp");
// copies to a local TEMP folder, returns the full path where
// it was copied to
string dest = s.CopyServerFileToLocal(filename, "test", ext);
MessageBox.Show("Copied file to " + dest);
You'll see a message like:
Copied file to C:\Users\sascrh\AppData\Local\Temp\SEG1896\ekecsy3k.2hj\test.csv
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Chris,
This is a wonderful way of transfer file from server to local. Very handy to use and much easier than I expected.
Thank you very much for this example!
Yihong
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Chris,
Have another question. In the Training book, page 4-11 (as shown in the attached), can you send me the more specific link to the Task API and Toolkit Documentation. From the link: http://go.sas.com/customtasksapi I cannot find what it is shown in the slide.
Thanks!
Yihong
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yihong,
It's the Reference Documentation link from that page. It's a ZIP file with a CHM (Microsoft Help file) and some PDFs. The CHM file has the reference info. After extracting it from the ZIP file, you might need to right-click on the CHM file, choose Properties and select Unblock in the security settings. Microsoft Windows often blocks CHM content from "untrusted" sources (the Internet).
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much Chris! This is very helpful!
Yihong
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Chris,
I have a question about reading the SAS Macro variable. See the following code. I have a method getMacro(string varName) from line 9. In line 1, I call the method to read AUTOMATIC macro variable SYSUSERID. It alwars works. In line 7, I call the same method again to read GLOBAL macro variable SASWORKLOCATION. It is not working. But if I add a submitter as shown in line 3 to line 5, it will work. It works for my purpose, but I like to know why it behaves like this. Can you help explain?
Thanks!
Yihong
============================================================================
public string userID = "";
public string wkg = "";
1 userID = getMacro("SYSUSERID"); MessageBox.Show(userID);
3 SAS.Tasks.Toolkit.SasSubmitter submitter = new SAS.Tasks.Toolkit.SasSubmitter("SASApp");
4 string log;
5 submitter.SubmitSasProgramAndWait("%let wkc = %sysfunc(getoption(work));", out log);
6
7 wkg = getMacro("SASWORKLOCATION");
8
9 public string getMacro(string varName)
10 {
11 // Consumer.AssignedServer is the active server from SAS EG
12 SasServer s = new SasServer(Consumer.AssignedServer);
13 string vName = s.GetSasMacroValue(varName); MessageBox.Show(vName);
14 return vName;
15 }
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yihong,
The macro variables that SAS Enterprise Guide creates when it submits a program/task are also "cleared" at the end of the task. You'll see the following code added to each task/program in the log:
%LET _CLIENTTASKLABEL=;
%LET _CLIENTPROJECTPATH=;
%LET _CLIENTPROJECTNAME=;
%LET _SASPROGRAMFILE=;
This means that these macro variables are NOT defined when you check their values "in between" tasks.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
But macro variable SASWORKLOCATION is not cleared, right? Whe I check its value with %put &SASWORKLOCATION, it is always there in the SAS EG session, before or after I run the customer task.
Also, when I add the line 3 - 5 in my code (a submitter), the line 7 ( wkg = getMacro("SASWORKLOCATION"); ) works. Why submit a line of SAS code in the middle makes it works? Thanks!Yihong- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yihong,
Ah, I see what you mean. The GetSasMacroValue is actually performing a data query, something like this:
sashelp.vmacro where name="SASWORKLOCATION";
I'm not sure why it would behave differently -- except this: the SASWORKLOCATION macro variable is not initialized until after the first program or task is submitted from SAS Enterprise Guide. So if you start EG then immediately run your custom task, which then queries this value before anything else happens -- then the value will not yet have been set.
Chris