SAS Communities Library

We’re smarter together. Learn from this collection of community knowledge and add your expertise.
BookmarkSubscribeRSS Feed

Query Data Using Natural Language in SAS Viya with Azure OpenAI

Started ‎01-09-2025 by
Modified ‎01-09-2025 by
Views 607

Imagine you're working with a new dataset in SAS Viya but lack the time or skills to code. With Azure OpenAI Assistants function calling, you can ask questions directly from a Jupyter Notebook. The assistant translates your queries into SAS code, executes it, and delivers the results back in natural language. This interaction empowers you to explore data intuitively, focusing on insights rather than coding syntax.

 

01_BT_Query-Data-and-Data-Analysis-in-SAS-Viya-with-Azure-OpenAI-Assistant-API-with-Function-Calling-1024x576.png

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

Data querying and data analysis using natural language on any dataset is now possible with Azure OpenAI's Assistant API, specifically through its Function Calling feature. This allows users to analyze data in SAS Viya without writing complex SAS code. By leveraging a simple Jupyter Notebook, users can interact with the assistant to ask questions in natural language. The assistant translates these questions into SAS code, executes it in the SAS Viya environment, and returns the results in a user-friendly format. SASPy, a Python package, facilitates the connection between Python and SAS Viya, enabling seamless data querying and analysis. This approach supports various data sources, including SAS libraries, databases, and cloud data sources, offering flexibility and efficiency. It empowers users to perform complex data analyses without technical skills, focusing on insights rather than programming.

 

02_Data Analysis with SAS Viya - Azure OpenAI Assistants Function Calling.mp4
Video Player is loading.
Current Time 0:00
Duration 5:35
Loaded: 0%
Stream Type LIVE
Remaining Time 5:35
 
1x
    • Chapters
    • descriptions off, selected
    • captions off, selected
    • en (Main), selected
    (view in My Videos)

     

    Behind the Scenes

     

    How does this happen? The process begins by connecting to a SAS Viya environment using SASPy, a Python package that facilitates interaction with SAS from Python. Before diving into data analysis, metadata about the dataset is gathered and incorporated into the Azure OpenAI Assistant's context. This metadata is crucial as it ensures the assistant generates precise and relevant SAS code without fabricating column names or data types.

     

    The assistant's true power lies in its ability to convert natural language questions into SAS queries using the function execute_SAS_code. This function executes the generated SAS code within the SAS Viya environment, and the results are returned to the user. By injecting metadata early, the assistant is equipped to generate accurate queries, preventing errors and enhancing the overall reliability of the analysis process.

     

    Video Player is loading.
    Current Time 0:00
    Duration 0:00
    Loaded: 0%
    Stream Type LIVE
    Remaining Time 0:00
     
    1x
      • Chapters
      • descriptions off, selected
      • captions off, selected
        (view in My Videos)

         

        Conclusion

         

        By leveraging the Azure OpenAI Assistants API and SAS Viya, data querying becomes accessible and efficient, even for those without technical expertise. This integration simplifies complex data queries into conversational interactions, democratizing data analysis and empowering a wider audience to make informed decisions. The future of data querying is here, and it's conversational, intuitive, and incredibly powerful.

         

        Additional Resources

         

        The approach is similar with the LangChain agents described in previous posts. The difference is that Microsoft offers now an alternative to LangChain through the Azure OpenAI Assistants API.

         

         

        Other posts:

         

         

        Thank you for your time reading this post. If you liked the post, give it a thumbs up! Please comment and tell us what you think about having conversations with your data. If you wish to get more information, please write me an email.

         

         

        Find more articles from SAS Global Enablement and Learning here.

        Version history
        Last update:
        ‎01-09-2025 12:28 AM
        Updated by:
        Contributors

        sas-innovate-white.png

        Special offer for SAS Communities members

        Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

         

        View the full agenda.

        Register now!

        SAS AI and Machine Learning Courses

        The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

        Get started

        Article Tags