简体   繁体   English

SAS连接到Teradata-使用2个帐户(切换)

[英]SAS connect to Teradata - Using 2 accounts (switch)

Can someone please help? 有人可以帮忙吗? I have not used SAS in a few years and need some assistance with connecting to Teradata. 几年来我没有使用过SAS,并且在连接Teradata时需要一些帮助。

I want to connect to Teradata using ACCT1 if the time of day is between 7pm-6:59am or with Acct2 if the time of day is between 7am-6:59pm. 如果一天中的时间在7 pm-6:59am之间,我想使用ACCT1连接到Teradata;如果一天中的时间在7 am-6:59pm之间,我想使用Acct2连接到Teradata。

%let
    acct1="mismktdev"
        acct2="mismktprod"


%include
%macro t_cnnct;  
    options nomprint;
    connect to teradata (tdpid="&tpidxyz" user="&misuid"
    password="&mispwd" account="&acct1"  mode=teradata);
    options mprint;

proc sql;
  connect to teradata (user="&terauser" password="&terapwd"  mode=teradata);
  execute (SET QUERY_BAND = 'Application=PrimeTime;Process=Daily;script=pt_add_history_v30.sas;' for session ) by teradata;
  %mend t_cnnct;

proc sql;
    Sel * from tblname;

You can use %let timenow=%sysfunc(time(), time.); 您可以使用%let timenow=%sysfunc(time(), time.); to get the time at which the program is running and then in you macro do something like : 获取程序运行的时间,然后在您的宏中执行以下操作:

%macro test();
%let timenow=%sysfunc(time(), time.);
%put &timenow;
%if (&timenow > '19:00'T and &timenow < '06:59'T) %then %do;
    /* Your Code for 7pm - 6:59am Here*/
%end; 

%else %do;
    /*Code for 7am - 6:59pm here*/
%end;
%mend;

%test();

Your idea to use SAS macro variables is just right. 您使用SAS宏变量的想法是正确的。 Here is a macro to define all the global SAS macro variables you need (including changing the "account" string): 这是一个宏,用于定义所需的所有全局SAS宏变量(包括更改“帐户”字符串):

%macro t_cnnct;
%global tdserver terauser terapwd teraacct teradb;

%let tdserver=myTDPID;
%let terauser=myuserID;
%let terapwd=mYTDpassword;
%let teradb=myTDdatabase;

%let now=%sysfunc(time());
%if    &now >= %sysfunc(inputn(07:00,time5.)) 
   and &now <= %sysfunc(inputn(19:00,time5.))
  %then %let teraacct=mismktdev;
  %else %let teraacct=mismktprod;
%mend t_cnnct;

Note the SAS macro variable values are specified without double-quotes! 请注意,指定的SAS宏变量值不带双引号! Use double-quotes when they are referenced in your code. 在代码中引用双引号时,请使用双引号。

Next, just run the macro before your PROC SQL code to set the variables and use those variables in your connect string: 接下来,只需在PROC SQL代码之前运行宏即可设置变量并在连接字符串中使用这些变量:

%t_cnnct;

proc sql;
  connect to teradata (user="&terauser" password="&terapwd" account="&teraacct" 
                       server="&tdserver" mode=teradata);
  execute (
     SET QUERY_BAND = 'Application=PrimeTime;Process=Daily;script=pt_add_history_v30.sas;' for session
     ) by teradata;

  create table mySASds as
  select *
  from connection to teradata (
     select *
     from &teradb..tablename
     );
quit;

Note that the tdpid= option you were using is an alias for the server= option (which I prefer). 请注意,您使用的tdpid=选项是server=选项的别名(我更喜欢)。 Also, the query band you set will remain in effect for the entire PROC SQL run. 同样,您设置的查询范围将在整个PROC SQL运行中保持有效。

And here is an example of a SAS libref that uses the same macro variables: 这是使用相同宏变量的SAS libref的示例:

libname myTD teradata user="&terauser" password="&terapwd" account="&teraacct" 
                      server="&tdserver" database="&teradb" mode=teradata);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM