2017-06-08 15 views
0

を解決しません。マクロ変数は、私はマクロ「quantplot」を実行すると、私は写真のような問題に遭遇SAS

実際に起こっているように見えるのは、この形式の式recode_ &変数、out_ &変数などが正しい値を返すように見えないということです。単にrecode_と読み、マクロ変数を無視しているだけです。

data test (drop=i); 
do i=1 to 1000; 
a=round(uniform(1)*4,.01); 
b=round(uniform(1)*10,.01); 
c=round(uniform(1)*7.5,.01); 
u = rand("Uniform"); 
y=floor((2)*u); 
output; 
end; 
stop; 
run; 

%macro percentiles(indep_var=,num_groups=); 
%let recodes=recode_%sysfunc(tranwrd(&indep_var,%str(),%str(recode_))); 
proc rank data=test out=test groups=7; 
var &indep_var; 
ranks &recodes; 
run; 
%mend; 
%percentiles(indep_var=a b c); 

そしてまた、現在動作していないマクロのコード:

私は、サンプルデータのための次のコードを提供してきました。助けてください!

/*Plots to determine functional form for quantitative variables*/ 
%macro quantplot(indep_var=,dep_var=); 
    /* Count the number of words in the input */                                 
    %let count=%sysfunc(countw(&indep_var)); 
    /* Loop through the total number of values */                       
    %do i = 1 %to &count;                            
     %let variables=%qscan(&indep_var,&i,%str()); 
     %put(&variables); 
     proc means data=test; 
     %put(&variables); 
      class recode_&variables; 
      var &dep_var; 
      output out = out_&variables mean = pby_&variables; 
     run; 
     data p_&variables; 
      set out_&variables; if _type_=1; 
      lnp = log(pby_&variables/(1-pby_&variables)); 
     run; 
     ods graphics on; 
      proc gplot data = p_&variables; 
       symbol value = star i=join; 
       plot lnp*recode_&variables; 
       plot pby_&variables*recode_&variables; 
      run; 
     ods graphics off; 
    %end; 
%mend; 
%quantplot(indep_var=a b c,dep_var=y); 
+0

質問には関係ありませんが、gplotではなくsgplotを使用することをお勧めします。あなたはより良いグラフィックス、より多くのコントロールを取得し、私の意見で使用するのが簡単です。 – Reeza

+0

https://gist.github.com/statgeek/7cffd06ebc3bc9c78b4f6a5b4538b053 – Reeza

+0

procランクを自動化するための私のバージョンのマクロ。 – Reeza

答えて

5

問題は、%のて、qscan使用して引用マクロを導入しているということです。時々

%let variables=%qscan(&indep_var,&i,%str()); 

とをこのそれがあるべきときに自動的に削除されていない引用、それはのトークン化破る:

class recode_&variables; 

MPRINTが正しく表示されているがエラーが発生した場合は、マクロの引用符の問題が疑われるはずです。あなたは値を自分でUNQUOTEすることができ、次のいずれか

class %unquote(recode_&variables); 

または%scan%qscanの使用を変更します。

%sysfunc(strip())を使用するソリューションは、%sysfunc()が値の引用符を付けないために機能します。

+0

これは素晴らしい答えでした。私はこれらのことの多くを認識していませんでした。ありがとうございました! – NicChik

関連する問題