オブザベーション数(=レコード数)を求めます。
元データ
sashelp.classのオブザベーション数を求めてみます(19レコード)。
proc print data = sashelp.class;
run;

その1:SQLで求める
proc sql;
select count(*) into: aaa trimmed
from sashelp.class;
quit;
%put num_of_count =[&aaa.];

※trimmedで余分な空白を削除しています。
その2:データステップで求める
data _NULL_;
if 0 then set sashelp.class nobs = bbb;
call symputx("aaa", bbb);
stop;
run;
%put num_of_count =[&aaa.];

※「if 0 then データセット名」でデータセットの定義部分のみを読み込みます。
stopステートメントでデータセットの読み込みを中断します。
その3:proc contentsで求める
proc contents data = sashelp.class out = tmp_class_1;
run;
data tmp_class_2;
set tmp_class_1(obs = 1);
call symputx("aaa", NOBS);
run;
%put num_of_count =[&aaa.];

call symputx(“aaa”, NOBS);は
call symput(“aaa”, strip( put(NOBS, best.) ));と書いても同じです。
※コメントでご指摘を受けたため一部修正しています。ありがとうございます。
業務では帳票の母数を求めるときによく利用します。
ほぼ定型文での処理ですが、CROによっても記述が異なるのでおもしろいです。
コメント
その3の補足
call symput(“aaa”, strip(NOBS));
では暗黙の変換が起こってしまうので、正しくは以下かと思います。
call symput(“aaa”, strip(put(NOBS,best.)));
ご指摘ありがとうございます!
修正しました。