How to suppress error messages from SAS proc sql execute statement - sas

I use SAS proc sql execute statement to run sql and access tables on Oracle server. In order to let the script run automatically, I normally drop tables or indice before creating them. Sometimes however, when the drop sql code runs, the table or index doesn't exist. An error message will be logged in SAS about dropping something that doesn't exist. But since the SAS code will continue after the drops, this kind of error message doesn't matter at all. I want to suppress these error messages, stop SAS from logging them because I don't care about them. How can I do this in proc sql?
Thanks for any help.

I'm not aware of an option to supress this single type of error. There are a couple of options though.
The best bet is to clean up your code so you check to see if the data set exists before trying to act on it:
%if %sysfunc(exist(&name_of_data_set)) %then %do;
You could also redirect all logging during these steps where you get messages you don't want with proc printto, but you would potentially lose valuable information.

Related

Error while loading data in Teradata using proc append (SAS EG 14.1)

I am getting below error while appending data in a Teradata table from SAS
ERROR: Teradata connection: No more room in database TINYDB. Correct error and
restart as an APPEND process with option TPT_RESTART=YES. Since no checkpoints were
taken, if the previous run used FIRSTOBS=n, use the same value in the restart.
I don't know why i am getting this error for one table, because i am able to append other Teradata tables.
I am using simple proc append
proc append data=table1 base=table2 (MULTILOAD=YES TPT=YES) force;
run;
Please suggest why its giving above error just for one table, while appending in other Teradata tables is working fine.
Thanks
#
Adding
Just one explanation, if i remove (MULTILOAD=YES TPT=YES) from the Proc Append Statement, then it will work, but will take huge amount of time

Killing an entire sas process

I have developed a SAS process in Enterprise Guide 7.1 that sends e-mails daily (if need be).
The way it works is this:
[external program] generates a file which specifies who needs to be emailed and the subject matter
.
My sas process then looks like this:
1. import this file.
2. manipulate this file.
3. generate emails based on contents of manipulated file.
The problem is, everything crashes if the original file imported in step 1 is empty. Is there a way to run the import, check if the dataset is empty, and then if it is terminate the entire sas process tree?
Thank you in advance, I've been searching but to no avail.
Best way would be to put step 2 and 3 completely in a macro and only execute it when step1 dataset is not empty.
step 1 import file in dataset mydata
data _null_;
set mydata nobs=number;
call symput('mydata_count', number);
stop;
run;
%macro m;
%if &mydata_count > 0 %then %do;
step 2 manipulate this file
step 3 generate emails
%end;
%mend;
%m;
As alternative you could use the statements "Endsas" or "abort" which both terminate your job and session but they can have unwanted sideeffects, you can find these statements and information about them easily when googling for them together with keyword sas.
Although the two statements do what you originally wanted, i would recommend the logical approach i posted as first, because you have more control about what is happening that way and you can avoid some bad side-effects when working with the statements
IMO a better way is to start using a macro like %runquit;. See my answer here. https://stackoverflow.com/a/31390442/214994
Basically instead of using run; or quit; at the end of a step you use %runquit;. If any errors occurred during that step then the rest of the SAS process will be aborted. If running in batch, the entire process is killed. If running interactively, code execution stops, but your interactive session remains open.
EDIT: This assumes you get some kind of error message or warning if the file is empty.

how to get the return codes from SAS pass-through SQL to Teradata ?

In SAS 9.2, how do I get the return codes / error messages from explicit pass-through sql to teradata? Printed in log or output or something.
I already got a small query to work fine, but having some trouble with a more complex one. Debugging would be much easier with the error messages.
Tried the sqlxmsg and sqlxrc that are used when querying db2, but of course those don't work... haven't found any documentation on this. (I'm quite new to Teradata)
Use the SASTRACE option to bring back debugging messages from Teradata.
http://support.sas.com/documentation/cdl/en/acreldb/63647/HTML/default/viewer.htm#a000433982.htm
This document supports and shows an example of it in use on explicit pass-through SQL:
https://support.sas.com/resources/papers/TroubleshootingSASandTeradataQueryPerformanceProblems.pdf
N.B. If you are using this option on large sets of data, be careful to choose the options wisely or you will create huge logs
This was the code, and now after shutting and restarting SAS it works fine!
Seems I had some process hanging somewhere...
rsubmit sashost;
proc sql;
connect to teradata (user=&terauser password=&terapass server=&teraserv mode=teradata);
create table test as
select * from connection to teradata
(select x
from y.z
where c);
%put &sqlxmsg;
%put &sqlxrc;
disconnect from teradata;
quit;
proc download data=test out=locallib.test; run;
endrsubmit;

SAS Conditional Libname Assignments and Error Log

I am using SAS Enterprise Guide 6.1 and am utilizing the "Submit SAS Code when server is connected" capability under Tools, SAS Programs to submit all of my personal credentials, libnames. Yes, I know there is probably an easier way to do this with SAS Management Console, but that is not an option right now.
I have several Teradata libraries I need to assign within each project, but the problem is that sometimes I (or more commonly somebody else on my team) will change my password and forget to change it in the start-up code. This results in several incorrect attempts and locks me out immediately. I wish to do a few things:
Create a conditional libname assignment that will execute all the libnames if the credentials are correct.
If the credentials are incorrect, the libnames are not executed (so that I don't lock myself out).
Since the SAS code in the "Submit SAS Code when server is connected" section doesn't seem to generate a log, I wish to send myself an email with the SAS Log attached (only if the credentials fail).
Kill the Server connection (if credentials error out) to avoid further attempts to assign libraries.
Here is my attempt, I'm having trouble attaching the log and setting up the email statement.
*Define personal credentials;
%let myemail=gollum#middleearth.com;
filename temp email "&myemail";
*Define Teradata credentials;
%let tera_user=Gollum; /*Teradata Username*/
%let tera_pwd=#filthy_hobbitses; /*Teradata Password*/
*Conditionally assign libraries;
%macro libsetup();
libname library1 teradata user=&tera_user password="&tera_pwd" tdpid=terap schema=library1 fastload=yes bulkload=yes fastexport=yes;
%if &syslibrc=0 %then
%do;
libname library2 teradata user=&tera_user password="&tera_pwd" tdpid=terap schema=library2 fastload=yes bulkload=yes fastexport=yes;
libname library3 teradata user=&tera_user password="&tera_pwd" tdpid=terap schema=library3 fastload=yes bulkload=yes fastexport=yes;
*more library statements here;
%end;
%else
%do;
data _null_;
file temp
subject="TERADATA CREDENTIALS ERROR"
attach=("put SAS LOG filename here");
put 'Teradata Login Failed. SAS LOG Attached.';
%abort abend;
%end;
%mend libsetup;
%libsetup;
Thanks.
Can't tell if your looking for suggestions on alternative approaches, or for help with the emailing.
For emailing, something like below (untested) should work:
filename __mymail email
to="gollum#middleearth.com"
from="gollum#middleearth.com"
subject="credential error"
attach="/home/mylog.log"
;
data _null_;
file __mymail;
put "Hi!";
run;
Note the server where SAS is executing has to have access to a mail server, and actual code needed may vary with mail protocol, etc.
For attaching the log, will probably need to use PROC PRINTTO to write your log to a file, and then use PROC PRINTTO again to let go of the file before you email it.
HTH

SAS: Track progress inside of a Proc Sql statement

I found this piece of code online
data _null_;
set sashelp.class;
if mod(_n_,5)=0 then
rc = dosubl(cats('SYSECHO "OBS N=',_n_,'";'));
s = sleep(1); /* contrived delay - 1 second on Windows */
run;
I would like to know if you had any idea of how to adapt this piece to a proc sql statement, so I could track the progress of a long query...
For example
proc sql;
create table test as
select * from work.mytable
where mycolumn="thisvalue";
quit;
and somewhere in the statement above we would include the
rc = dosubl(cats('SYSECHO "OBS N=',_n_,'";'));
You wouldn't be able to directly check the progress of a SQL query, unfortunately (if it's operating on SAS datasets, anyway), except by monitoring the physical size of the table (you can do a directory listing of your WORK directory, or depending on how it's building the table, the Utility directory). However, it may or may not be linear; SQL might, for example, use a hash strategy which would not necessarily take up disk space until it was fairly close to being done.
For SQL, you're best off looking at the query plan to tell how long something's going to take. There are several guides out there, such as The SQL Optimizer Project, which explains the _METHOD and _TREE options among other things.