I have a store procedure in Teradata and I trying execute with "PROC SQL" in SAS but I don't have results.
libname S_SQUEMA teradata server="100.00.00.100" user=##### pwd=#### schema=S_SQUEMA fastload=YES;
PROC SQL;
CALL S_SQUEMA.SP_TEST(year);
QUIT;
Thanks.
To run something in Teradata you need to connect to Teradata using a CONNECT statement and then push the Teradata code to the database using the EXECUTE statement. So your code will look something like this:
proc sql ;
connect to teradata ..... ;
execute ( call S_SQUEMA.SP_TEST(year) ) by teradata;
quit;
If you already ran your LIBNAME statement to define your S_SQUEMA libref then you can just use that to make the connection.
proc sql ;
connect using S_SQUEMA ;
execute ( call S_SQUEMA.SP_TEST(year) ) by S_SQUEMA;
quit;
Related
I would like to ask you how to move a table from SAS to TeradataSQL Assistant.
What I have done in SAS is to define a libname, then create the table that I want to move in Teradata.
libname NAME "/path"
proc sql;
create table WORK.EXAMPLE as(
select *
from DATASET
);
quit;
However, I do not know if I need to connect SAS to Teradata in this way:
libname NAME teradata USER=tduser PASSWORD=tdpasswd SERVER=TDServ ;
proc sql;
connect to teradata (
tdpid=“” user=“” password=“”);
create table WORK.EXAMPLE as
select * from connection to teradata
(select * from DATASET
); quit;
My questions are:
in the second libname, where should I consider the path?
which one of the code above should I consider and why?
how can I 'call' this table in Teradata? I tried with SELECT * FROM WORK.EXAMPLE, but it does not exist.
Thank you for your help.
You can either connect to Terdata using the LIBNAME statement
libname mylib TERADATA .... ;
or the CONNECT statement in PROC SQL.
proc sql;
connect to teradata .... ;
In fact you can even use the libref created in a previously created LIBNAME statement in your connect statement.
libname mylib TERADATA .... ;
proc sql;
connect using mylib ;
Generally I find it easiest to use PROC APPEND to copy data into Teradata.
libname td TERADATA ... ;
libname mysas 'path to where my SAS datasets live';
proc append base=td.target_table data=mysas.source_table force;
run;
If the target table doesn't exist then SAS will create it. (In which case take care as you might not want the default variable types or the primary index that will get created that way.).
On the SAS server we have a library that contains thousands of datasets. I want to catalog the contents of a subset of these, all of which have names that begin with "prov". Can I use a wildcard to specify this?
I tried:
PROC CONTENTS DATA=library.prov*;
RUN;
But that just produces a log with this error message:
ERROR: File LIBRARY.PROV.DATA does not exist.
I also tried library.prov%, and that gave the same error.
There are over 100 datasets that start with "prov" so I really don't want to have to do them one at a time. Any ideas?
Depending on what information you want that the CONTENTS procedure produces you could just use the DICTIONARY metadata views.
proc sql ;
create table want as
select *
from dictionary.columns
where libname = 'LIBREF'
and memname like 'PROV%'
;
quit;
Use a WHERE data set option.
proc contents data=sashelp._all_ noprint out=class(where=(memname like 'CLASS%'));
run;
When you specify the keyword _ALL_ in the PROC CONTENTS statement, the step displays a list of all the SAS files that are in the specified SAS library.
Example :
PROC CONTENTS DATA=libref._ALL_ NODS;
RUN;
But to open only the datasets that begin with prov you can use the SQL and add CONTAINS to WHERE e.g:
proc sql ;
create table mytables as
select *
from dictionary.tables
where libname = 'WORK'
order by memname ;
quit ;
Now just run:
PROC CONTENTS DATA mytables;
RUN;
I may be using a different version of SAS check if you have the library SASHELP if so try this based on my note in your comment on the previous response you may see that this works out for you:
proc sql outobs=100;
create table see as
select distinct libname,memname,crdate,modate from sashelp.vtable
where libname='LIBRARY' and memname like 'PROV%'
order by memname;
quit;
SAS Libname Statment
QUERY_BAND= LIBNAME Option
Generate
SET QUERY_BAND="BAND;" FOR SESSION;
I need to generate this :
SET QUERY_BAND='BAND’; FOR SESSION VOLATILE;
Whitch statment should I to use?
Statement like QUERY_BAND_VOLATILE does not exist.
Your query_band expression is incorrect. Use smth like below, and run it within the Proc SQL as Richard suggested.
SET QUERY_BAND = 'BAND=1;' FOR SESSION VOLATILE;
proc sql;
connect to teradata as tdd (server=&SERVER. user=&HCUSER. password=&HCPASS.);
execute(SET QUERY_BAND = 'BAND=1;' FOR SESSION VOLATILE; ) by tdd;
disconnect from tdd;
quit;
We currently use the %runquit macro function as detailed here (http://analytics.ncsu.edu/sesug/2010/CC07.Blanchette.pdf). The %runquit macro is shown below. It basically stops running any more SAS code when an error is encounterd, and can be used as a replacement for both the run and quit statements:
%macro runquit;
; run; quit;
%if &syserr %then %abort cancel;
%mend;
Because using the outobs statement in proc sql triggers a system error (even when the nowarn option is specified) it means we are unable to use the %runquit macro when we need to use the outobs= option.
The below example will generate the following warning message:
proc sql noprint outobs=3 /*nowarn*/;
create table tmp as
select age, count(*) as freq
from sashelp.class
group by 1
order by 2 desc
;
%runquit;
WARNING: Statement terminated early due to OUTOBS=3 option.
Thank you SAS for the completely unnecessary warning. The behaviour is obviously expected because I explicitly wrote code to ask for it. I don't see warnings given when we specify inobs= and outobs= on a set statement. Why does proc sql get the special treatment?
Is there any way to disable the warning issues by the outobs= option in proc sql? Alternatively, is there another way to limit the output rows from proc sql that will not generate an error?
Assuming you are okay with the full SQL statement executing, you can get around this with a data step view that contains the obs limitation.
proc sql noprint ;
create table tmp as
select age, count(*) as freq
from sashelp.class
group by 1
order by 2 desc
;
%runquit;
data tmp_fin/view=tmp_fin;
set tmp(obs=3);
%runquit;
Or make the SQL statement a view and use the data step to make the data set.
proc sql noprint ;
create view tmp_view as
select age
, count(*) as freq
from sashelp.class
group by 1
order by 2 desc
;
quit;
data tmp;
set tmp_view(obs=3) ;
run;
This might be one of your options considering I/O is not a huge constraint, here the reset outobs= option with nowarn does the trick but at IOs cost.
proc sql;
create table test as
select * from sashelp.class;
reset outobs=10 nowarn;
create table test1 as
select * from sashelp.class;
quit;
How can I call an Oracle stored proc from SAS to pass values and return values. I have SAS/ACCESS and running SAS 9.3
Thanks
Dan
This should work:
proc sql;
connect to oracle (user="oracleUserName" password="pass" path="serverPath" CONNECTION=GLOBAL CONNECTION_GROUP = SASAML);
execute( execute MyPackage.MyProcedure(¶m1, ¶m2) ) by oracle;
/* param1 and param2 are macro variables here */
disconnect from oracle;
quit;
This should work fine in SAS 9.2 and above using ODBC passthrough.
Here's a similar discussion with relevant links:
http://communities.sas.com/message/114296#114296
I'll try and come back sometime to surmise the linked article in this answer...
Pass-through stored procedure execution does not support output parameters. But if you need only one output parameter, a workaround is to use a function and "SELECT FROM dual" query. Here is in example (it uses one input parameter that is passed in from a macro variable).
%let a = 'ddd';
proc sql;
connect to oracle as ora2 (user=xxx password=xxx path="xxx");
select * from connection to ora2 (
SELECT test_fun(p_a => &a.) FROM dual
);
disconnect from ora2;
run;