---
title: SAS and API
tags:  #[第9回大阪sas勉強会]  
author: [森岡裕[SASユーザー総会世話人]](https://www.docswell.com/user/6484025)
site: [Docswell](https://www.docswell.com/)
thumbnail: https://bcdn.docswell.com/page/PEXPV3Q67X.jpg?width=480
description: [第9回大阪SAS勉強会]小澤　義人
published: March 26, 24
canonical: https://www.docswell.com/s/6484025/5GXDDJ-2024-03-26-061943
---
# Page. 1

![Page Image](https://bcdn.docswell.com/page/PEXPV3Q67X.jpg)

SAS and API
Application Programming Interface
Program を簡単にしたいなとの思惑で複雑になってしまう仕組み。


# Page. 2

![Page Image](https://bcdn.docswell.com/page/3EKDQY9GJD.jpg)

本日の内容 スライドが細かいので、中身はスキップしていきます。
APIって何？
１）APIって何？（全体像）
２）APIって何？ 少し具体的にしてみましょう。
ウェブAPI（Web API）:
ライブラリAPI:
OSレベルのAPI:
3）図示
OSレベルのAPI:
ライブラリAPI:
ウェブAPI（Web API）:
4）本題
1. Web API 共通事項
2. 翻訳 API をつかってみる （Deepl翻訳）
3. CDISC LIBRARY API を使ってみる。
5）終わり


# Page. 3

![Page Image](https://bcdn.docswell.com/page/L73RP9W5J5.jpg)

APIって何？（全体像）
ChatGPTに聞いてみました。
API（Application Programming Interface）は、
プログラム同士が相互に通信するためのインターフェースや手段を提供するものです。
APIは、ソフトウェアコンポーネントが他のコンポーネントと対話するための約束や規約を定義し、それを通じて情報やサービスをやり取りします。
1
APIは、さまざまな目的で使用されます。
以下はそのいくつかの例です：
ウェブAPI（Web API）:
ウェブAPIは、ウェブ上でサービスを提供するために使用されます。
これは、HTTPプロトコルを通じてデータを送受信し、通常はJSONやXML形式で情報をやり取りします。
例えば、Google Maps APIは地図データを提供し、Twitter APIはツイートの取得や投稿を可能にします。
2 ライブラリAPI:
プログラミング言語やフレームワークが提供する関数やメソッドなどの集合体もAPIと呼ばれます。
開発者はこれらのAPIを使用して、特定の言語やフレームワークでの機能を実現できます。
3 OSレベルのAPI:
オペレーティングシステムは、アプリケーションがハードウェアやシステムリソースにアクセスできるようにするためのAPIを提供します。
例えば、Windows APIやPOSIX APIがこれに該当します。
★ APIは、開発者が他のソフトウェアやサービスと効果的に対話し、連携するための効果的な手段を提供することで、
ソフトウェア開発やシステム統合の際に非常に重要な役割を果たしています。


# Page. 4

![Page Image](https://bcdn.docswell.com/page/87DYLGKY7G.jpg)

APIって何？ 少し具体的にしてみましょう。
説明:
1
ウェブAPI（Web API）:
・ Google Maps APIは地図データを提供し
・ Twitter APIはツイートの取得や投稿を可能にします。
＝＞ 今回は SAS で 下記２つのWeb APIを使ってみます。
1. 翻訳 API をつかってみる （Deepl）
2. CDISC LIBRARY API を使ってみる。
独り言：
1) SAS と Python
2) SAS と R
&lt;= DATASET JSON など扱うときには Python をCall したほうが良いのかな。
&lt;= R も使ってみたいな。
API？ではない？それともAPI？ Viya になったら簡単になるのかな。
＝＞まあでも。。。 手になじむと SASは 便利かな。


# Page. 5

![Page Image](https://bcdn.docswell.com/page/VJP623K2E8.jpg)

APIって何？ 少し具体的にしてみましょう。
説明:
2
ライブラリAPI:
・プログラミング言語やフレームワークが提供する関数やメソッドなどの集合体もAPIと呼ばれます。
・開発者はこれらのAPIを使用して、特定の言語やフレームワークでの機能を実現できます。
＝＞ 実際には、個別のライブラリを Call するよりは Comamnd.com , cmd.com , bash , shell 等の
汎用的な プログラムを呼び出すことが多いです。
・SAS では SYSTEM関数 、 CALL SYSTEMルーチン などで Shell を呼び出すことで
動作している OSに依存しないプログラムが書けます。
ひと昔前はEXCEL の DDEを使った プログラムを書くことが多かったです。
1. X コマンドなどで Ecxcel を起動して SASのコマンドを受ける体制を整えて。
2. Filename DDE ‘system|excel’ のような感じで excel にコマンドを送っていました。
DDEが Windows 3.1 の機能(API と言っていいか否か不明ですが。。。)ですので
このようなプログラムは OS 依存（Windows 3.1 の機能である DDE を有した環境）
でないと実行できませんでした。 ライブラリAPIとOSレベルAPIの混在のような感じです。
3. Windows 3.1 の DDE はWindows から Excel などのアプリケーションにデータを送り込むだけ（または取り込むだけ）の機能しかなかったように思います。
タイミングや実行環境のチェックのプログラムや対応が必要でした。
タイミングの処理のため適当な時間 SASで時間をつぶす（ x= sleep (10) ）とか、起動した excel には触らないとか、SASProgram が複雑になってました。
4. OLEなどで起動しているアプリケーションと起動IDを交換して、起動状況を確認することができるようになったのですが・・・ あまり OLEを使ったProgram はSAS
では浸透しなかったように感じます。
ただ、オブジェクト指向のプログラムの始まりですので、SAS/AFでは SCL （Screen Control Language）が搭載され
概念的にはVBA のようなオブジェクト指向のプログラムが書ける のですが、記法としてVBA より書きにくいものであったり、情報が少なく何かをしてもすぐ壁に突
き当たってしまいます。


# Page. 6

![Page Image](https://bcdn.docswell.com/page/2EV3D4VX7Q.jpg)

APIって何？ 少し具体的にしてみましょう。
説明:
3
OSレベルのAPI:
Windows API は Windows のネイティブの機能を直接呼び出せるため，痒いところに手の届くアプリケーションを開発でき
ます。でも OSレベルのAPI は複雑なので簡単なアプリケーションの開発でも苦労を伴います。
MS-DOS以前の PC98 では BIOS割り込みに INT 1Bh (DISK BIOS) （INT というのが割り込み）
割り込み Table の 1Bh 番地を CALL する（そこに JMPする）とその周りの引数に応じた対応をします。
＝＞ フロッピーディスコのコピーツールやコピーガードを外す際に INT 1B 周りを調査するもので、PC98の割り込み
テーブルが広く知られるようになったのではないでしょうか。（INT 1B はOSの公開というよりはPC98の仕様 ）
MS-DOS では割り込み Table の 21h 番地が整備されました（INT21H で Call するのが MS-DOS というイ
メージでした） これは、公開された仕様です。
=&gt; INT21 を含む種々の公開仕様（API）を元にサードパーティでいろいろなソフトが作られています。
遠い昔の記憶なので、若干あいまいですがお許しください。


# Page. 7

![Page Image](https://bcdn.docswell.com/page/57G3Y1LRJL.jpg)

APIって何？
説明:
SAS
OSレベルのAPI:


# Page. 8

![Page Image](https://bcdn.docswell.com/page/4EQ5MDYYJP.jpg)

APIって何？
説明:
SAS
ライブラリAPI:


# Page. 9

![Page Image](https://bcdn.docswell.com/page/KJ49VZWZ71.jpg)

APIって何？
最近、 SASpy というのを聞いたことがありますか？
これは SASシステムのための Python APIですね。
説明:
SASPy — saspy 5.4.4 documentation (sassoftware.github.io)
https://support.sas.com/en/software/saspy.html
SAS
ライブラリAPI:


# Page. 10

![Page Image](https://bcdn.docswell.com/page/LE1K3RYDJG.jpg)

APIって何？
説明:
本日、SASでやってみました～
的にご紹介するのが
Web API です。
SAS
ウェブAPI（Web API）:
HTTP:~~~~~~~


# Page. 11

![Page Image](https://bcdn.docswell.com/page/GEWDP1G8J2.jpg)

Web API 共通事項
１）接続先の URL を確認しよう。
２）接続の手順を確認しよう。
３）API-Key などのパスワードみたいなものが必要です。
４）いきなり SAS は難しいのでまずは curl コマンドで確認。
下記のような Web ページを眺めて、Curl の使い方に慣れておいたほうが何かと便利です。
curl コマンド 使い方メモ (https://qiita.com/yasuhiroki/items/a569d3371a66e365316f)
いつも ブラウザに入力している URL を コマンドラインから打ち込んでみると、画面にレスポンスか帰ってきます。
curl https://www.yahoo.co.jp
curl https://www.google.com
&gt;&gt; c:\Yahoo.html ファイルにしたければリダイレクトをしておけばファイルが作成
&gt;&gt; c:\Google.html
curl –help でオプションがリストされます。
HTTP/2
や HTTP/1.1 と Version の異なるプロトコルが混在しています。
https://www.kagoya.jp/howto/it-glossary/security/http-2/


# Page. 12

![Page Image](https://bcdn.docswell.com/page/47ZGKPL9E3.jpg)

Web API 共通事項
HTTP/2
や HTTP/1.1 と Version の異なるプロトコルが混在しています。
https://www.kagoya.jp/howto/it-glossary/security/http-2/
翻訳 API では http/2 が必要なので、curl も http/2 対応のものに Update しましょう。
使われている curl の確認には 下記のようなコマンドが使えます。
curl -si https://curl.se -o/dev/null -w &#039;%{http_version}\n’
私の環境ではデフォルトでは HTTP/1.1 でした。
（curl 8.4.0 (Windows) libcurl/8.4.0 Schannel WinIDN）
Http/２対応の ものに変更しました。 （同じ Versionですけど
8.4.0 (x86_64-w64-mingw32)


# Page. 13

![Page Image](https://bcdn.docswell.com/page/YJ6YQMWD7V.jpg)

翻訳 API をつかってみる
（Deepl）
https://www.deepl.com/ja/docs-api
まずはこのページの例を動かしましょう。
最初は Curl で動かします。
無料版のAPIをして 認証キーを入手しました。
無料版なので１か月 50万もじまでです。
SAS でごりごり動かすと、すぐ文字制限に到達してしまいます。
APIの Test としては分かりやすいですが、業務で使うなら 有料版？


# Page. 14

![Page Image](https://bcdn.docswell.com/page/GJ5GRZM8J4.jpg)

やってみよう。 Deepl 翻訳 Curl
例
curl -X POST &#039;https://apifree.deepl.com/v2/translate&#039; \
--header ‘Authorization: DeepL-Auth-Key
????????-????-???? –????-????????????:fx’ \
--data-urlencode &#039;text=Hello, world!&#039; \
--data-urlencode &#039;target_lang=DE&#039;
EXAMPLE RESPONSE
{
&quot;translations&quot;: [
{
&quot;detected_source_language&quot;: &quot;EN&quot;,
&quot;text&quot;: &quot;Hallo, Welt!&quot;
}
]
}
1) Windows 環境の Command.com では文字区切りは
シングルクオートではなくダブルクオートでした。
2) Windows 環境の Command.com では
Multiline は扱えませんでした。
curl -X POST &quot;https://api-free.deepl.com/v2/translate&quot; -header &quot;Authorization: DeepL-Auth-Key ????????-????-????
–????-????????????:fx&quot; --data-urlencode &quot;text=Hello,
world!&quot; --data-urlencode &quot;target_lang=DE&quot;
1) 英語(EN)から 日本語(JA)にしてみます。
curl -X POST &quot;https://api-free.deepl.com/v2/translate&quot; -header &quot;Authorization: DeepL-Auth-Key ????????-????-????
–????-????????????:fx &quot; --data-urlencode &quot;text=Hello,
world!&quot; --data-urlencode &quot;target_lang=JA&quot;


# Page. 15

![Page Image](https://bcdn.docswell.com/page/LE3RP9WG75.jpg)

やってみよう。 Deepl 翻訳 Curl ファイルに書き出し
前の例ではコマンド内に &quot;text=Hello, world!&quot; というテキストを翻訳しました。
curl -X POST &quot;https://api-free.deepl.com/v2/translate&quot; --header &quot;Authorization: DeepL-Auth-Key ????????-????-???? –????-????????????:fx &quot; --data-urlencode &quot;text=Hello, world!&quot; --dataurlencode &quot;target_lang=JA&quot;
SASで扱うことと、コマンドラインの行数制限を考えると、翻訳の文書はファイルで送りたいです。
「Upload and Translate a Document」のコマンドをTestしてみます。
ファイル、ここでは C:\test\E_J.txt のファイルを翻訳します。 中身は [from file : Hello, world! ]です（文字数制限があるので簡単な物にしました。
curl -X POST &quot;https://api-free.deepl.com/v2/document&quot; --header &quot;Authorization: DeepL-Auth-Key ????????-????-???? –????-????????????:fx &quot; --form &quot;file=@C:\test\E_J.txt&quot; --form
&quot;source_lang=EN&quot; --form &quot;target_lang=JA&quot;
Uploadが成功すると ドキュメント番号とドキュメントキーが返ってきます。
{&quot;document_id&quot;:&quot;BB18858C48653C359ABDA058F3439C1F&quot;,&quot;document_key&quot;:&quot;84EAF22BED15C257A85AA1963B14840A1129F367AFB276DE518C7182C199A1F6&quot;}
このドキュメントキーを使って翻訳の状態を確認します。 Check Document Status
curl -X POST &quot;https://api-free.deepl.com/v2/document/BB18858C48653C359ABDA058F3439C1F&quot; --header &quot;Authorization: DeepL-Auth-Key ????????-????-???? –????-????????????:fx &quot; --dataurlencode &quot;document_key=84EAF22BED15C257A85AA1963B14840A1129F367AFB276DE518C7182C199A1F6&quot;
{“document_id”:“BB18858C48653C359ABDA058F3439C1F”,“sta tus”:“done”,“billed_characters”:25}
翻訳終了です。


# Page. 16

![Page Image](https://bcdn.docswell.com/page/8EDYLGKNEG.jpg)

WEB URL はだめだった～
結局 Windows /or os Shell から Curl をCallして情報を入手
＝＞ Curl の力を借りたライブラリAPI:って感じかな
できない
libname jsn ;
filename resp temp ;
proc http
method=&quot;post&quot;
url=&quot;https://api-free.deepl.com/v2/document/BB18858C48653C359ABDA058F3439C1F&quot;
out=resp;
headers
&quot;Authorization&quot;=&quot;DeepL-Auth-Key ????????????????????????????????????:fx&quot;
&quot;Accept&quot;=&quot;application/json&quot; ;
;
data-urlencode
&quot;document&quot;=&quot;document_key
84EAF22BED15C257A85AA1963B14840A1129F367AFB276DE518C7182C199A1F6&quot;
;
libname jsn JSON fileref=resp;
filename resp ;
こんな感じで対応
filename zz &#039;m:\zz.bat&#039; ;
data _null_ ;
length xx $1000. ;
file zz ;
Xx=&#039;curl –X POST https://api-free.deepl.com/v2/document/BB18858C48653C359ABDA058F3439C1F&#039; ;
put xx @ ;
xx=&#039;--header &quot;Authorization: DeepL-Auth-Key ????????????????????????????????????:fx &quot; --dataurlencode
&quot;document_key=84EAF22BED15C257A85AA1963B14840A1129F367AFB276DE518C7182C199A1F6&quot;&#039; ;
put xx ;
run ;
* x &#039;m:\zz.bat&#039; ;
filename listing pipe &quot;m:\zz.bat&quot; ;
data null ;
length inf $2000. ;
infile listing ;
input ;
inf= _infile_ ;
run ;
data null ; set null ;
retain flg 0 ;
if substr ( left (inf) , 1,1) =&#039;{&#039; then flg=1 ;
run ;
data null ; set null ;
if flg=1 then output ;
run ;


# Page. 17

![Page Image](https://bcdn.docswell.com/page/V7P623KNJ8.jpg)

だめだった～： SASは HTTP/1.1 準拠
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.
5/proc/n0t7v16eitluu2n15ffpfeafqszs.htm
HTTP/2 は使えない～


# Page. 18

![Page Image](https://bcdn.docswell.com/page/2JV3D4VYEQ.jpg)

それでも一連のプログラムを作成してみました。(1/3)
Shell Call は xから %sysexec に変更しています。
** https://blogs.sas.com/content/sgf/2020/07/30/curl-to-proc-http/ ;
%*--------------------------------;
%* Deepl 翻訳 ;
%*--------------------------------;
%*--------------------------------;
%*Upload and Translate a Document ;
%*--------------------------------;
%global respF ;
%let apik= ????????????????????????????????????:fx;
%let xfname =c:\test\E_J ;
%let xext =txt ;
%let xfile =&amp;xfname..&amp;xext.
;
%let outfile =&amp;xfname._JP.&amp;xext. ;
%let respF =c:\test\response.txt ;
%* ファイル削除 ;
data _null_;
fname=&quot;TMP&quot; ;
rc=filename(fname,&quot;&amp;respF.&quot; );
if rc = 0 and fexist(fname) then
rc=fdelete(fname);
run;
%*------------------------------------------------------------------*翻訳ファイルを UPLOAD の cURL コマンド
curl -X POST &quot;https://api-free.deepl.com/v2/document&quot; --header &quot;Authorization: DeepL-Auth-Key &amp;apik.&quot; --form &quot;file=@m:\xx.txt&quot; --form &quot;source_lang=EN&quot; --form &quot;target_lang=JA&quot;
* Response ;
{&quot;document_id&quot;:&quot;4BEDB9C25FA18321FFD731E624BC1CA4&quot;,&quot;document_key&quot;:&quot;6BE101ADBDB9262B7A63CDA3C3BC7B72CAA36A226 9932306FB84C38CA38E26F6&quot;}
-------------------------------------------------------%;;
data _null_;
%sysexec curl -Ss -o &quot;&amp;respF.&quot; -X POST &quot;https://api-free.deepl.com/v2/document&quot; --header &quot;Authorization: DeepL-Auth-Key &amp;apik.&quot; --form &quot;file=@&amp;xfile.&quot; --form &quot;source_lang=EN&quot; --form &quot;target_lang=JA&quot; ;
run;


# Page. 19

![Page Image](https://bcdn.docswell.com/page/5EG3Y1LW7L.jpg)

それでも一連のプログラムを作成してみました。(2/3)
%macro waitresp ( _respF=&amp;respF. , sleepsec=6 , noofwait=10 ) ;
%local _respF ;
%* response 待ち、6秒× 10回 ;
data _null_;
fname=&quot;TMP&quot; ;
do waitresp=1 to &amp;noofwait. ;
rc=filename(fname,&quot;&amp;_respF.&quot; );
put rc=;
if rc = 0 and fexist(fname) then stop ;
else do ;x=sleep(&amp;sleepsec.) ; end ;
put waitresp ;
end ;
run;
filename tmp ;
%mend ;
%waitresp ;
このサンプルでは下記のようなファイルが
作成されます。
Excel 、Word 、PDFでもOKだと思います。
翻訳前
翻訳後
%* response をデータにする ;
libname res json &quot;&amp;respF.&quot; ;
data docIDALL ; set res.alldata ; run ;
data docID ; set res.root ; run ;
libname res ;
proc sql noprint ;
select document_id , document_key into:document_idx, :document_keyx from docID
quit ;
%put &amp;document_idx. &amp;document_keyx ;
%* ファイル削除 ;
data _null_;
fname=&quot;TMP&quot; ;
rc=filename(fname,&quot;&amp;respF.&quot; );
if rc = 0 and fexist(fname) then
rc=fdelete(fname);
run;
このプログラムでは
一度ダウンロードされると
上書きされてしまうので要注意！
Document already downloaded


# Page. 20

![Page Image](https://bcdn.docswell.com/page/4JQ5MDYQ7P.jpg)

それでも一連のプログラムを作成してみました。(3/3)
%*--------------------------------;
%*Check Document Status ;
%*--------------------------------;
%*------------------------------------------------------------------curl -X POST &quot;https://api-free.deepl.com/v2/document/4BEDB9C25FA18321FFD731E624BC1CA4&quot; --header &quot;Authorization: DeepL-Auth-Key &amp;apik.&quot; --data-urlencode &quot;document_key=6BE101ADBDB9262B7A63CDA3C3BC7B72CAA36A2269932306FB84C38CA38E 26F6&quot;
{&quot;document_id&quot;:&quot;4BEDB9C25FA18321FFD731E624BC1CA4&quot;,&quot;status&quot;:&quot;done&quot;,&quot;billed_characters&quot;:42436}
-------------------------------------------------------%;;
data _null_;
%sysexec curl -Ss -o &quot;&amp;respF.&quot; -X POST &quot;https://api-free.deepl.com/v2/document/&amp;document_idx.&quot; --header &quot;Authorization: DeepL-Auth-Key &amp;apik.&quot; --data-urlencode&quot;document_key=&amp;document_keyx.&quot; ;
run;
%waitresp ;
%* response をデータにする ;
libname res json &quot;&amp;respF.&quot; ;
data docStatusAll ; set res.alldata ; run ;
data docStatus ; set res.root ; run ;
libname res ;
proc sql noprint ;
select document_id , status into:document_idxx , :statusxx from docStatus ;
quit ;
/*** STATUS =ERROR STATUS=translating seconds_remaining=1023 STATUS=done billed_characters=
**/
%put &amp;document_idxx. &amp;statusxx. ;
%* ファイル削除 ;
data _null_; fname=&quot;TMP&quot; ; rc=filename(fname,&quot;&amp;respF.&quot; ); if rc = 0 and fexist(fname) then
rc=fdelete(fname);
run;
%macro ckstatus ( ck=&amp;statusxx.) ;
%if &quot;&amp;ck.&quot;=&quot;done&quot; %then %do ;
%*--------------------------------;
%*Download Translated Document ;
%*--------------------------------;
%put &quot;&amp;outfile.&quot; ;
%put &quot;&amp;ck.&quot; ;
%put &quot;&amp;document_idxx.&quot; ;
%put &quot;&amp;document_keyx.&quot; ;
data _null_;
%sysexec curl -Ss -o &quot;&amp;outfile.&quot; -X POST &quot;https://api-free.deepl.com/v2/document/&amp;document_idxx./result&quot; --header &quot;Authorization: DeepL-Auth-Key &amp;apik.&quot; --data-urlencode&quot;document_key=&amp;document_keyx.&quot; ;
run;
%* %waitresp ;
%end ;
%else %do ;
%put &#039;まだ翻訳が終わってません &#039; ;
%end ;
%mend ;
%ckstatus ;


# Page. 21

![Page Image](https://bcdn.docswell.com/page/K749VZWYE1.jpg)

もっと良い例は？
Web APIっぽいのはないかな？？？？
SASで直接使いたい


# Page. 22

![Page Image](https://bcdn.docswell.com/page/LJ1K3RYN7G.jpg)

CDISC LIBRARY API を使ってみる。(1/5)
SASで直接使いたい Web API（情報収集＆APIKey入手)
API Portal
CDISC Library Browser
CDISC LIBRARY
まずは 情報収集
（ユーザー登録などを済ませてから
API Portalにアクセス。）
CDISC Data Standards Browser
https://api.developer.library.cdisc.org/
API Key
API Portal から API Key を入手します。
API Tester
API Documentation
How-to articles


# Page. 23

![Page Image](https://bcdn.docswell.com/page/GJWDP11M72.jpg)

CDISC LIBRARY API を使ってみる。(2/5)
Program sample 入手
How-to articles
Getting Started: Programmatically connect to CDISC Library API
Python
SAS
R
Java
XQuery
プログラム中のAPI Keyは例示サンプルです、API key の取得は必須です。


# Page. 24

![Page Image](https://bcdn.docswell.com/page/4EZGKPPMJ3.jpg)

CDISC LIBRARY API を使ってみる。 (3/5)
Program 実行
%let apik=???????????????????????????????? ;
filename response TEMP;
proc http
url=&#039;https://library.cdisc.org/api/mdr/products&#039;
out=response;
headers
/* fictitious API key used, real one can be obtained through API
Management Developer Portal */
/* change to &quot;application/xml&quot; for response in XML format */
&quot;api-key&quot;=&quot;&amp;apik.&quot;
&quot;Accept&quot;=&quot;application/json&quot;;
run;
data _null_;
infile response;
input;
put _infile_;
run;
SAS のLogWindowにJson データが出力されています。


# Page. 25

![Page Image](https://bcdn.docswell.com/page/Y76YQMM5EV.jpg)

CDISC LIBRARY API を使ってみる。 (４/5)
Requestの URLは？ API Tester で Request URLを探す。
①
例えば、CT(Controlled Terminology )を入手)
③
① CDISC LIBRARY API
② GET /mdr/ct/packages/{package}
package には SDTM-CT-2019-12-20 のような記載、
現在最新は sdtmct-2023-12-15
・大文字小文字の Case sencitive ではないようです。
③
うまくいけば、青色の結果が返ってきます。
②


# Page. 26

![Page Image](https://bcdn.docswell.com/page/G75GRZZG74.jpg)

CDISC LIBRARY API を使ってみる。 (5/5)
Program マクロ化
①マクロ定義 CDISCAPI
%macro CDISCAPI ( xurl , apikey=&amp;apik. ) ;
filename resp TEMP ;
proc http
url=&quot;&amp;xurl.&quot;
out=resp;
headers
/* fictitious API key used, real one can be obtained through API Management Developer Portal */
/* change to &quot;application/xml&quot; for response in XML format */
&quot;api-key&quot;=&quot;&amp;apikey.&quot;
&quot;Accept&quot;=&quot;application/json&quot;;
run;
/* Assign a JSON library to the HTTP response */
libname jsn JSON fileref=resp;
proc sql ;
create table _tname as
select * from sashelp.vtable where libname=&#039;JSN&#039;
;
quit ;
filename ff catalog &#039;work.tmp.json_sas.source&#039; ;
data _null_ ; set _tname ;
file ff ;
put &#039;data &#039; memname &#039; ; set &#039; libname +(-1) &#039;.&#039; memname &#039; ; run ;&#039; ;
run ;
%inc ff ;
filename ff ;
libname jsn ;
filename resp ;
%mend ;
③データセットができています。
Codelistcode 1081 レコードと
codelistcodeを親に持つ
CTコードの1081個のデータセット
②マクロ利用 CDISCAPI
（CT(Controlled Terminology )を入手）
libname API ‘C:\test’ ; * 保存先 ;
%global apik ;
%let apik=???????????????????????????????? ;
%macro hang ; proc datasets lib=work kill NOLIST; quit; %mend ;
%hang ; %CDISCAPI ( https://api.library.cdisc.org/api/mdr/ct/packages/sdtmct-2023-12-15 ) ;
data api.CodelistsCode_20231215x ;set Codelists ;
codelistcode
= conceptId
;
CodelistExtensible = extensible
;
CodelistName
= definition
;
CDISCSubmissionValue = submissionValue ;
keep
codelistcode
CodelistExtensible
CodelistName
CDISCSubmissionValue
;
run ;
/* 個々のコードリスト確認(Test)
%hang ; %CDISCAPI ( https://library.cdisc.org/api/mdr/ct/packages/sdtmct-2023-12-15/codelists/C67152 ) ;
data api.term_C67152 ;set root ; run ;
*/
/* 全部のコードリスト入手 */
filename tmp catalog &#039;work.tmp.tmp.source&#039; ;
data _null_ ; set api.CodelistsCode_20231215 ;
file tmp ;
put &#039;%hang ; %CDISCAPI ( https://api.library.cdisc.org/api/mdr/ct/packages/sdtmct-2023-12-15/codelists/&#039; codelistcode
&#039; ) ;&#039; ;
put &#039;data api.term_&#039; codelistcode +(-1) &#039;_&#039; CDISCSubmissionValue &#039; ;length codelistcode $20. ; set terms ; codelistcode=&quot;&#039;
codelistcode &#039;&quot; ; run ;&#039; ;
run ;
%inc tmp ;
filename tmp;


# Page. 27

![Page Image](https://bcdn.docswell.com/page/9J2YDRRDJR.jpg)

終わり
終わりに、最近では Rest [ful] API
というのも耳にしますね。
REST（Representational State Transfer）とは
Wikipedia（https://ja.wikipedia.org/wiki/Representational_State_Transfer）では、
Representational State Transfer (REST、レスト) は、ウェブAPI（ウェブアプリケーションプログラ
ミングインタフェース）の定義に使用されるアーキテクチャスタイル（共通仕様）であり、同時
にウェブのような分散ハイパーメディアシステムのためのソフトウェアアーキテクチャのスタイ
ルのひとつでもある。
この語はHTTPプロトコル規格の主要著者の一人であるロイ・フィールディング（英語版）がウェ
ブについて書いた2000年の博士論文で初めて現れ、ネットワーキングコミュニティの中ですぐに
広く使われることになった。
～～～～～～～～
以下略
コメント：単なるWeb APIよりは REST APIのほうが、仕様がしっかりしているのでプログラムは使いまわせる？


# Page. 28

![Page Image](https://bcdn.docswell.com/page/DEYG2DDMEM.jpg)

ありがとうございました。
ご質問、ご意見、提案等があればお気楽にご連絡ください。
**********************************************
小澤 義人
国立大学法人千葉大学 医学部附属病院 特任助教
臨床試験部生物統計室
E-mail: Yoshihito.Ozawa@chiba-u.jp
*********************************************


