Using the Scoring Functions

The scoring functions are available to use in any SQL expression in the same way that Teradata built-in functions are used. For an example, see Model Publishing Example.
There are four ways to see the scoring functions that are created:
  • From Teradata, you can log on to the database using a client tool such as BTEQ and submit an SQL statement. The following example assumes that the model name that you used to create the scoring functions is mymodel.
    bteq .logon myserver/myuserid,mypassword;
      select * from dbc.tables where tablename like '%mymodel%';
  • From SAS you can use SQL procedure code that produces output in the LST file. The following example assumes that the model name that you used to create the scoring functions is mymodel.
    proc sql noerrorstop;
      connect to teradata (user=user password=pass server=server);
      select *
         from connection to teradata
         (select tablename,tablekind,databasename,LastALterTimeStamp
          from dbc.tables where
          databasename='sas' and tablename like '%mymodel%'
          and tablekind='F');
    
    disconnect teradata;
    quit;
    
    You can also use the SASTRACE and SASTRACELOC system options to generate tracing information. For more information about these system options, see the SAS 9.2 Language Reference: Dictionary.
  • You can look at the SampleSQL.txt file that is produced when the %INDTD_PUBLISH_MODEL macro is successfully run. This file can be found in the output directory (OUTDIR argument) that you specify in the macro.
    The SampleSQL.txt file contains basic code that, with modifications, can be used to run your score code inside Teradata.
    For example, the SampleSQL.txt file refers to an ID column in allmush1_intab that is populated with a unique integer from 1 to n, with n being the number of rows in the table. The ID column uniquely identifies each row. You would replace the ID column with your own primary key column.
    Note: The function and table names must be fully qualified if the functions and tables are not in the same database.
    The following example assumes that the model name that you used to create the scoring functions is allmush1.
    drop table allmush1_outtab;
    create table allmush1_outtab(
     id integer
    ,"EM_CLASSIFICATION" varchar(33)
    ,"EM_EVENTPROBABILITY" float
    ,"EM_PROBABILITY" float
    );
    insert into allmush1_outtab(
     id
    ,"EM_CLASSIFICATION"
    ,"EM_EVENTPROBABILITY"
    ,"EM_PROBABILITY"
    )
    select id,
     allmush1_em_classification("BRUISES"
    ,"CAPCOLOR"
    ,"GILLCOLO"
    ,"GILLSIZE"
    ,"HABITAT"
    ,"ODOR"
    ,"POPULAT"
    ,"RINGNUMB"
    ,"RINGTYPE"
    ,"SPOREPC"
    ,"STALKCBR"
    ,"STALKROO"
    ,"STALKSAR"
    ,"STALKSHA"
    ,"VEILCOLO")
      as "EM_CLASSIFICATION",
     allmush1_em_eventprobability("BRUISES"
    ,"CAPCOLOR"
    ,"GILLCOLO"
    ,"GILLSIZE"
    ,"HABITAT"
    ,"ODOR"
    ,"POPULAT"
    ,"RINGNUMB"
    ,"RINGTYPE"
    ,"SPOREPC"
    ,"STALKCBR"
    ,"STALKROO"
    ,"STALKSAR"
    ,"STALKSHA"
    ,"VEILCOLO")
      as "EM_EVENTPROBABILITY",
     allmush1_em_probability("BRUISES"
    ,"CAPCOLOR"
    ,"GILLCOLO"
    ,"GILLSIZE"
    ,"HABITAT"
    ,"ODOR"
    ,"POPULAT"
    ,"RINGNUMB"
    ,"RINGTYPE"
    ,"SPOREPC"
    ,"STALKCBR"
    ,"STALKROO"
    ,"STALKSAR"
    ,"STALKSHA"
    ,"VEILCOLO")
      as "EM_PROBABILITY"
    from allmush1_intab ;
    
  • You can look at the SAS log. A message is printed to the SAS log that states whether a scoring function is successfully or not successfully created or replaced.