828 Views
April 15, 25
スライド概要
[第11回大阪sas勉強会]
SAS言語を中心として,解析業務担当者・プログラマなのコミュニティを活性化したいです
Implementing Local LLM Execution with SAS HTTP Procedure in VS Code Yohei Takanami (高浪 洋平) Statistical and Quantitative Sciences (SQS) Japan Takeda Pharmaceutical Company April 16, 2025
Disclaimer Please note that contents, views and opinions of this presentation are of the solely responsibility of the author and in no way represent the organization to which the author belongs. 2
Outline • Background • Set up SAS and AI Toolkit in Visual Studio (VS) Code • Local Large Language Model (LLM) execution with SAS HTTP Procedure • Summary 3
Background • Recently, Large Language Models (LLMs) play an important role to enable statisticians and statistical programmers to develop tools and applications that can streamline business processes and daily works in the creation of statistical deliverables such as specifications, datasets, analysis report. • Visual Studio (VS) code offers development environment for various programming languages such as R, Python, SAS, and users can easily access LLMs through API using programming code. • In this presentation, setup of SAS in VS Code, installation of extensions such as AI Toolkit, examples of SAS code using HTTP procedure to run local LLM will be provided. For users who do NOT have SAS Viya license 4
Set up SAS and AI Toolkit in VS Code • What is VS Code? • Extension(拡張機能)を実装することで、R、SAS、Python等、様々なプログラミング 言語の開発環境を提供する。 • GitHub Copilotを実装することで、Codingやエラー修正のみならず、調べものもすぐに 回答してくれるため、作業効率が格段に向上する。 5
Set up SAS and AI Toolkit in VS Code • Installation of SAS extension in VS Code • SASのExtensionをInstallすることで、VS Code上にSAS実行環境を構築できる。 • 但し、SAS OnDemand for Academicsのみを使用しているユーザーは、現時点では接続できない。 6
Set up SAS and AI Toolkit in VS Code • SAS in VS Code • デスクトップ環境と同様に SASを実行することが可能 7
Set up SAS and AI Toolkit in VS Code Deepseekの軽量版もあるが、何となくCodingのサ ポートは現時点ではPhi-4-miniの方が優れてそう。 • Installation of AI Toolkit extension in VS Code • 様々なLLMをローカルにインストールできる(今回は軽量LLMのMicrosoft Phi-4-mini) • 3.8Bパラメーターの軽量モデル。コンパクトなサイズにもかかわらず、推論、数学、コー ディング、命令実行、関数呼び出しといったテキストベースのタスクでは、大規模言語モ デルに引けを取らないパフォーマンスを発揮する(らしい)。 https://forest.watch.impress.co.jp/docs/news/1666053.html 8
Set up SAS and AI Toolkit in VS Code • Installation of AI Toolkit extension in VS Code • “Playground”でLLMの動作確認ができる。 9 パフォーマンスはPCのスペックに依存する。 今回は、CPU: Intel Core Ultra 5 135U, RAM: 16GB, W/O GPU/NPU
SAS HTTP Procedure • What is HTTP? • HTTP(Hyper Text Transfer Protocol)は、WebサーバとWebクライアント(例:Webブラウザ)が データを送受信するために使用されるプロトコル。 • 主に、Webページを構成するHTMLファイルや画像、動画などのデータをやり取りする際に利用 される。 • SAS HTTP Procedure • HTTPリクエストを作成して、Webサーバー・サービスからデータを取得したり送信する。 Request 今回はどちらも Localに存在する。 Response PROC HTTP URL="URL-to-target" <options>; DEBUG options; HEADERS "HeaderName"="HeaderValue" <"HeaderName-n"="HeaderValue-n">; SSLPARMS encryption-options; 10 PROC HTTP URL="URL-to-target</redirect/n>“ <METHOD=<">http-method<">> <IN=<fileref | FORM (arguments) | MULTI <options> (parts) | "string">> <OUT=fileref> ;
Local LLM Execution with SAS HTTP Procedure in VS Code Execution flow of local LLM with SAS Create Prompt file HTTP Procedure • Simple Data Step to create test data in JSON format • Model information Responses (JSON) • Execute LLM from SAS • Minimal options in HTTP Statement VS Code Output from LLM Output RTF file 11 • JSON engine in Libname statement HTTP Procedure Prompts (JSON) • Output Prompts and answers in RTF format Phi-4-mini (Local LLM)
Local LLM Execution with SAS HTTP Procedure in VS Code • Create a dataset of Prompts /* Define the LLM endpoint URL */ %let llm_url = "http://localhost:5272/v1/chat/completions" ; %let _DIR = %str(Folder Path) ; /* Create prompt data */ data prompts; length prompt $200. ; input prompt &; No = _N_ ; datalines; Provide R code to generate continuous variable data and perform t-test to compare two treatment groups within 1000 characters. Provide R code to generate binary test data and perform chi-square test to compare two treatment groups within 1000 characters. ; run; Need to develop Programming code to perform xxx analysis in a clinical trial with conditions xxx… 12 Responses (JSON) VS Code HTTP Procedure Prompts (JSON) Phi-4-mini (Local LLM)
Local LLM Execution with SAS HTTP Procedure in VS Code
Responses
(JSON)
• Export prompts and model information to JSON file
data _null_;
set prompts ;
if _N_=&I ;
file llmin&I;
put '{';
put ' "model": "Phi-4-mini-cpu-int4-rtn-block-32-acc-level-4-onnx",';
put ' "messages": [';
put '
{"role": "user", "content": "' prompt '"}';
put ' ],';
put ' "temperature": 0.8,';
put ' "max_tokens": 500';
put '}';
run;
VS Code
プロンプトを一つずつJSONファイル形式で送付する
13
HTTP Procedure
Prompts
(JSON)
Phi-4-mini
(Local LLM)
Local LLM Execution with SAS HTTP Procedure in VS Code Responses (JSON) • HTTP Procedure to send prompt file to local LLM filename llmin&I "&_DIR.\llm_input&I..JSON" ; filename llmout&I "&_DIR.\llm_output&I..JSON" ; filename headers&I "&_DIR.\llm_headers&I..JSON"; VS Code HTTP Procedure /* Use PROC HTTP to send the request and receive the response */ proc http url=&llm_url method=POST in = llmin&I /* Send the input as a form parameter */ out = llmout&I /* Save the response to a file */ headerout=headers&I ct="application/json" ; run; PCのスペックにもよりますが、今回の質問であれば、 それほど時間はかかりません(10秒/prompt程度、RTF 作成まで40~50秒程度)。 14 Prompts (JSON) Phi-4-mini (Local LLM)
Local LLM Execution with SAS HTTP Procedure in VS Code Responses (JSON) • SAS Output in RTF format VS Code HTTP Procedure Prompts (JSON) 15 Phi-4-mini (Local LLM)
Summary • VS Codeは様々なプログラミング言語の開発環境を提供してくれる。 • PC SAS同様、SASを快適に動かすことができる。 • 但し、SAS OnDemand for Academicsのみを使用しているユーザーは、現時点では接続できない。 • LLMをダウンロード・インストールし、Local PC上で簡単に実行することができる。 • GitHub Copilotの力を借りて、様々な業務効率化につながる可能性がある。 • 専門外のProgramming言語の習得にも役立つ(将来的には1人QCも可能?)。 • SASでのLLM実行プロセス • SAS Viyaがなくても、HTTPプロシジャでLLMを実行し、結果を取得することが可能。 • SASユーザーにとっては、LLM実行時の前処理や後処理を効率的に進めることができる。 • 巷にあまり情報がないので、今後、本勉強会やSASユーザー総会で活用事例がどんどん共有される とAI時代でもSASユーザーの活躍の場が広がるかもしれない。 16
References • SAS Extension for Visual Studio Code • https://sassoftware.github.io/vscode-sas-extension/ • SAS HTTP Procedure • https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n0bdg5vmrpyi7jn1pbgbje2atoov.htm • Article of Phi-4-mini • https://forest.watch.impress.co.jp/docs/news/1666053.html 17
Local LLM Execution with Python OpenAI Library in VS Code • Sample Python Code Responses (TEXT) Phi-4-mini (Local LLM) VS Code OpenAI Library Prompts (JSON) 19