Cant read in .csv file - sas

I am opening a new program in SAS Enterprise Guide using file -> new -> program.
Now I would like to a load .csv file from my desktop using the following code:
proc import datafile="C:\Users\M.van.der.Peet\Desktop\test.csv"
out=shoes
dbms=csv
replace;
getnames=no;
run;
proc print;
run;
When I run this I get the following error however:
ERROR: Physical file does not exist, C:\Users\M.van.der.Peet\Desktop\test.csv.
But the file is there :). Any thoughts on how I get a better understanding of why this is not working? Is there an ls() like function to see which files are stored in a dir?

If your EG session is connected to a remote SAS server (such as a Linux server) your code will not work.
Basically, when you press submit in EG, it uploads the code to the SAS server, executes the code, and downloads the results and log to the EG client. Since the remote server cannot see files on your local C: drive, you will get an error if you try to read a file on C:.
You can upload the file to the remote server, and it will work. Or if you look at the EG tasks in the menus, I'm sure there is an IMPORT task or similar name which would work. The task works by uploading the input file for you before the SAS code is submitted. I don't use the menus, so can't give you the details.

Enterprise Guide is typically installed on UNIX/Linux Server. You have to FTP the file i.e. upload the file using a FTP client like WinSCP or UltrEdit from Windows to a location on UNIX. Then you have to provide that path on your program.

Related

SAS stored process to a web service link

I have created a SAS stored process and I need to attach it to a web service link which I intend to use it as an input in a python program .
I would really appreciate if I could get help in creating a web service from a SAS stored process .
Thank you,
Nishant
You need to create a Stored Process in SAS Management Console, and assign it to use the Stored Process Server (not Workspace Server). Ensure it has the 'streaming output' checkbox selected.
The SAS code behind this Stored Process should then send the output (that you wish to receive from your python program) to the _webout fileref, eg:
data _null_;
file _webout;
put 'Hello python!';
run;
The %stpbegin and %stpend macros should NOT be used.
To reference the Stored Process just call the URL with your Stored Process name & path in the _program parameter, as follows:
http://[yourMachineName]:8080/SASStoredProcess/do?_PROGRAM=/Your/MetadataPath/YourSTPName
Easiest is to use the SAS Stored Process Web App. It allows you to call a stored process via URL. You should read (http://support.sas.com/documentation/cdl/en/stpug/68399/HTML/default/viewer.htm#n0mbwll43n6sw3n1jhcfnx51i8ze.htm).
From there, use the Python requests library.

Proc http with https url

So, I want to use Google Url shortener Api, and I try to use
proc http
so, when I run this code
filename req "D:\input.txt";
filename resp "D:\output.txt";
proc http
url="https://www.googleapis.com/urlshortener/v1/url"
method="POST"
in=req
ct="application/JSON"
out=resp
;run;
(where D:\input.txt looks like {"longUrl": "http://www.myurl.com"} ) everything works greate on my home SAS Base 9.3. But, at work, on EG 4.3, I get:
NOTE: The SAS System stopped processing this step because of errors.
and no possible to debug. After googling, I found, that I have to set java system option like this
-jreoptions (-Djavax.net.ssl.trustStore=full-path-to-the-trust-store -Djavax.net.ssl.trustStorePassword=trustStorePassword)
But, where I can get "the certificate of the service to be trusted"- and password to it?
Edit: As I noticed in comments below, my work SAS installed into server, so I didn't have direct access to configuration. Also, It isn't good idea to change servers config. So, I try to google more, and found beautiful solution using cUrl, without X command (cause it block in my EG). Equivalent syntax is:
filename test pipe 'curl -X POST -d #D:\input.txt https://www.googleapis.com/urlshortener/v1/url --header "Content-Type:application/json"';
data _null_;
infile test missover lrecl= 32000;
input ;
file resp;
put _infile_;
run;
Hope it help someone
Where to get the certificate
Open the URL that you want the certificate from via Chrome. Click on the lock file in the URL bar, click on "details" tab and then click on "Save as file" in the bottom right. You will need to know what trust store you are going to use at this stage. See the following step.
The password and trust store is defined by you. It is in most cases nothing more than an encrypted zip file. There are a lot of tools out there that allow you to create a trust store, encrypt it and then import the certificates into it. The choice will depend on what OS you are using. There are some java based tools that OS independent, for example Portecle. It allows to define various trust stores on different OS and you can administer them remotely.
Regards,
Vasilij

SAS 9.3 email attachment

Since upgrading to SAS 9.3, i'm only able to send emails within rsubmit, which isnt a problem... however i'm unable to attach local files, please can someone assit?
RSUBMIT;
FILENAME outmail EMAIL
SUBJECT="Daily report attached"
TO= ("xxxxx#xx.com")
ATTACH= "C:\Users\one\Desktop\Cars.xls";
DATA _NULL_;
FILE outmail;
PUT "Hello All,";
PUT ;
PUT "Please find attached the Cars report.";
PUT ;
PUT "Regards";
PUT ;
RUN;
I receive the following error message in the log:
ERROR: Error opening attachment file C:\Users\one\Desktop\Cars.xls.
ERROR: Physical file does not exist, /home/one/C:\Users\one\Desktop\Cars.xls.
Any help is much apriciated.
Thank you
Your RSUBMIT is being submitted on a server, so inside the RSUBMIT the paths are local to the server. Unless it can see your desktop (ie, via a mapped drive) it won't be able to access files on the local machine. You would have to upload them to the server first.

Why LOAD DATA LOCAL INFILE will work from the CLI but not in application?

The problem:
My C++ application connects to a MySQL server, reads the first/header line of each db export.txt, makes a create table statement to prepare for the import and executes that against the database (no problem with that, the table appears just as intended) -- but when I try and execute the LOAD DATA LOCAL INFILE to import the data into the newly created table, I get the error "The used command is not allowed with this MySQL version". But, this works on the CLI! When I execute this command on the CLI using mysql -u <user> -p<password> -e "LOAD DATA LOCAL INFILE 'myfile.txt' INTO TABLE mytable FIELDS TERMINATED BY '|' LINES TERMINATED BY '\r\n';" it works flawlessly?
The Situation:
My company gets a large quantity of database exports (160 files/10gb of .txt files that are '|' delimited) from our vendors on a monthly basis that have to replace the old vendor lists. I am working on a smallish C++ app to deal with it on my work desktop. The application is meant to set up the required tables, import the data, then execute a series of intermediate queries against multiple tables to assemble information in a series of final tables, which is then itself exported and uploaded to the production environment, for use in the companies e-commerce website.
My Setup:
Ubuntu 12.04
MySQL Server v. 5.5.29 + MySQL Command Line client
Linux GNU C++ Compiler
libmysqlcppconn is installed and I have the required mysqlconn library linked in.
I have already overcome/tried the following issues/combinations:
1.) I have already discovered (the hard way) that LOAD DATA [LOCAL] INFILE statements must be enabled in the config -- I have the "local-infile" option set in the configuration files for both client and server. (fixed by updating the /etc/mysql/my.cnf with "local-infile" statements for the client and server. NOTE: I could have used the --local-infile=1 to restart the mysql-server, but this is my local dev environment so I just wanted it turned on permanently)
2.) LOAD DATA LOCAL INFILE seems to fail to perform the import (from the CLI) if the target import file does not have execute permissions enabled (fixed with chmod +x target_file.txt)
3.) I am using the mysql root account in my application code (because its my localhost, not production and this particular program will never run on a production server.)
4.) I have tried executing my compiled binary program using the sudo command (no change, same error "The used command is not allowed with this MySQL version")
5.) I have tried changing the ownership of the binary file from my normal login to root (no change, same error "The used command is not allowed with this MySQL version")
6.) I know the libcppmysqlconn is working because I am able to connect and perform the CREATE TABLE call without a problem, and I can do other queries and execute statements
What am I missing? Any suggestions? Thanks in advance :)
After much diligent trial and error working with the /etc/mysql/my.cfg file (I know this is a permissions issue because it works on the command line, but not from the connector) and after much googling and finding some back alley tech support posts I've come to conclude that the MySQL C++ connector did not (for whatever reason) decide to implement the ability for developers to be able to allow the local-infile=1 option from the C++ connector.
Apparently some people have been able to hack/fork the MySQL C++ connector to expose the functionality, but no one posted their source code -- only said it worked. Apparently there is a workaround in the MySQL C API after you initialize the connection you would use this:
mysql_options( &mysql, MYSQL_OPT_LOCAL_INFILE, 1 );
which apparently allows the LOAD DATA LOCAL INFILE statements to work with the MySQL C API.
Here are some reference articles that lead me to this conclusion:
1.) How can I get the native C API connection structure from MySQL Connector/C++?
2.) Mysql 5.5 LOAD DATA INFILE Permissions
3.) http://osdir.com/ml/db.mysql.c++/2004-04/msg00097.html
Essentially if you want the ability to use the LOAD DATA LOCAL INFILE functionality from a programmatic Connector API -- you have to use the mysql C API or hack/fork the existing mysql C++ api to expose the connection structure. Or just stick to executing the LOAD DATA LOCAL INFILE from the command line :(

Upload txt file to server

I want create a form to upload files (txt, xls) to the server, not the database.
Does anyone kown any example showing how I can do this?
In order to get the file on to the database server's file system, you would first have to upload the file to the database which it sounds like you are already familiar with. From there, you can use the UTL_FILE package to write the BLOB to the database server's file system.