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;
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!
コミュニティの基本的なガイドラインについてご説明します。まずは、こちらをご参照ください。
SAS Support CommunitiesのFAQはヘルプに記載されています。参照方法は、こちらからご確認ください。
Japan SAS Discussionページに質問や意見(メッセージ)を投稿/返信する方法を簡単にご説明します。