BookmarkSubscribeRSS Feed
AliZiya
Obsidian | Level 7

Hello All, 

I am trying to develop a new decision on SAS VIYA ID interface. There are several database tables on teredata. This tables inculudes the some available offers for each customers and I have to assign one offers to one customer randomly. This campaing works weekly. The first 3 offers can not given as new offer to customer next week. How I do that case on ID? How I will made a connection with database? Must it be on python file this all process including connection to db, conditions etc. ? I really appriciated if you guide me. 

1 REPLY 1
onuroruc
Fluorite | Level 6

Hi, you can use that code I shared below. First of all, you should connect to DB and query to your caslib. 

 

def execute():
'Output: customer_id'
import teradatasql

try:
conn = teradatasql.connect(
host='<host_name>',
user='<username>',
password='<password>',
database='<your_DB>'
)

cursor = conn.cursor()
cursor.execute("SELECT TOP 1 customer_id FROM <your_DB>.CUSTOMER")
row = cursor.fetchall()
cursor.close()
conn.close()

return row

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 514 views
  • 1 like
  • 2 in conversation