2016年2月27日 星期六

把sas資料集裡的某個值存成巨集變數(macro)


  • 把sas資料集裡的某個值存成巨集變數(macro)
使用
call symputx ("meanx", meanx);
就可以輕鬆存成巨集變數,symputx("巨集變數名稱",  變數名稱)。
巨集變數可以在任一個data step使用。


  • 範例:


proc means data = mysas.ex7_1 noprint;
 var Hardwood_Concentration__xi____;
 output out = add (drop = _type_ _freq_)
  mean(Hardwood_Concentration__xi____) = meanx;
run;

data _null_;
 set add;
 call symputx ("meanx", meanx);
run;

data nex7_1;
 set mysas.ex7_1;
 x1 = Hardwood_Concentration__xi____ - &meanx;
 x2 = (Hardwood_Concentration__xi____ - &meanx)**2;
run;

proc reg data = nex7_1;
 model Tensile_Strength__yi__psi_ = x1 x2;
run;
quit;
如果想要把變數減掉平均當作解釋變數如下圖,就可使用此方法。




資料集add:





%put &meanx; 

Related Posts:

  • SAS macro Ensemble Learning 以bootstrap方法產生多個資料集, 分別為每個資料集建立linear regression模型, 整合多個模型降低mse。 作者:jimmy 日期:2017/3/9 %macro my_bootstrap(data = , b = , obs =); %do bootstrap_i… Read More
  • Logistic Regression%macro Deviance_table(data, y, n, old_x) ; /********************************************************************************************************* … Read More
  • proc gtile sas help檔 內容 goptions reset = all device = java noborder; proc gtile data = sashelp.shoes; tile stores tileby = (region subsidiary) / colorvar =… Read More
  • sas macro logistic regression real adaboostdata comb_data; length comb_x $ 100; input comb_x $ @@; /*輸入所有x變數名稱,方便隨機抽取,放入不同模型裡*/ datalines; area da hfs i0 pa500 ; run; %macro logistic_real_ad… Read More
  • 將SAS報表匯出至外部檔案 可參考這篇(連結) PDF ods pdf file="C:\Users\139869\Desktop\深入解析SAS\test.pdf"; proc print data = sashelp.class; run; ods pdf close; ods pdf fil… Read More

0 意見:

張貼留言