BookmarkSubscribeRSS Feed

LABELの値を取得する関数

Started ‎03-03-2019 by
Modified ‎03-03-2019 by
Views 1,465

質問

DATAステップで変数ラベルを取得する際に、いったんマクロ変数として定義してから使用していますが、

もう少し簡単に変数ラベルを取得することはできないでしょうか?

 

回答

VLABEL関数を用いることで、容易に変数ラベルを参照・取得することができます。

SASデータセットの変数名と変数ラベルをログウィンドウへ出力するプログラムの例です。

 

<サンプルプログラム>

data test;       /* 変数ラベル付きデータセットの作成*/
  input id var $;
  label id="識別番号" var="文字列";
cards;
1 test1
2 test2
3 test3

;
run;

data _null_;     /* ラベルと変数の値をログウィンドウへ出力*/
   set test;
   put id var;           /* 変数値をログウィンドウへ出力*/
if _n_ = 1 then do; /* 1オブザベーション目のみの処理*/ lab_id = vlabel(id); /* 変数idのラベル値を取得*/ lab_var = vlabel(var); /* 変数varのラベル値を取得*/ put lab_id lab_var; /* 取得したラベル値をログウィンドウへ出力*/ end; run;
 

 

Version history
Last update:
‎03-03-2019 08:55 PM
Updated by:
Contributors

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Article Labels
Article Tags

SAS Support Communitiesのユーザーガイドライン


コミュニティの基本的なガイドラインについてご説明します。まずは、こちらをご参照ください。

詳細を読む

 

SAS Support CommunitiesのFAQ


SAS Support CommunitiesのFAQはヘルプに記載されています。参照方法は、こちらからご確認ください。

詳細を読む

 

質問や意見の投稿と返信方法について


Japan SAS Discussionページに質問や意見(メッセージ)を投稿/返信する方法を簡単にご説明します。

詳細を読む