2016-09-19 12 views
0

以下のprgは、変数のインスタンスを数えようとします。変数の頻度

%macro freq(dsn=,variable=,freq=,label); 

proc freq data = &dsn; 
tables &variable; 
run; 

%mend; 
%freq(dsn=fff,variable=ggg); 
+0

「ラベルを割り当てて表示する」とはどういう意味ですか?また、これはコードオンリクエストサービスではありません - あなたが特定のステップで立ち往生した場合は、これを自分で行い、特定の質問をするよう努力してください。 – user667489

答えて

0

フォーマットと印刷手順を追加することでこれを行うことができます。私はこれをテストし、あなたが達成しようとしていることが達成されたと信じています。

%macro freq(indsn=,variable=,freq=,label); 

/* Create a new format or label when a value falls between 
    0 and the user defined frequency. */ 
proc format; 
    value fmt 0-&freq. = "&label."; 
run; 

/* Run the frequency procedure and suppress the output 
    to a temporary data set. */ 
proc freq data = &indsn; 
tables &variable/noprint out=temp; 
run; 

/* Print the temporary data set and format the Count 
    variable (which was created in the freq procedure) 
    to the format, fmt, that we created. Finally, print only 
    records with a frequency less than the user defined 
    frequency. */ 
proc print data=temp noobs; 
    format count fmt.; 
    where count le &freq.; 
run; 

%mend; 

最近の編集では、これをデータステップとif文で実行できます。

%macro freq(indsn=,variable=,freq=,label); 

/* Run the frequency procedure and suppress the output 
    to a temporary data set. */ 
proc freq data = &indsn; 
tables &variable/noprint out=temp; 
run; 

/* Assign variable a new name if its frequency equals the 
    user defined frequency and only keep records with a count 
    less than or equal to the frequency. */ 
data temp; 
    set temp; 
if count le &freq.; 
if count = &freq. then &variable. = &label.; 
run; 

/* Print only the &variable variable. */ 
proc print data=temp noobs; 
var &variable.; 
run; 

%mend; 
+0

これは、これは立派な答えではありません。質問に答えるためのコードを提供するのは一般的には良いことですが、コードだけでなく、答えがどのように問題を解決し、どのように機能するかを記述することで、質問に答える必要があります。 – Joe

+0

@Joe反復可能な値が繰り返される回数を確認するにはコードを作成する必要があります。繰り返される値はfreq = 'パラメータ'と等しくなり、次にそれにdiffラベル/値「XYZ」を割り当てます。出力する際に​​は、繰り返される変数値の代わりに新しいラベルが表示されるはずです。 – Apache11

+0

@Joeあいまいな回答をおかけして申し訳ありませんが、私はコードが何をしているかについてもう少し明確にするように更新しました。 –

関連する問題