看板 Statistics 關於我們 聯絡資訊
[軟體程式類別]:SAS [程式問題]:macro [軟體熟悉度]:高(1年以上) [問題敘述]: 手上有一組原始資料,想要作10-fold cross-validation(交叉驗證,CV) 計算線性迴歸後得到一個R-square之後,將這些過程重複1000次, 以得到1000個R-square,再去計算平均值。 目前先寫了內部的程式(CV+PROC SURVEYSELECT+PROC REG) 現在想要重覆作1000次,因為會有1000個R-square,想將之存在同一個檔案 應該是要用macro寫... 初步跑一次發現output與log file跑出很多檔,如果另存到其他地方 是否會提升效率呢? [程式範例]: %macro boot ; %do x = 1 %to 1000; /*對raw data(檔名boottest)進行抽樣,出來的檔為xv*/ %let k=10; %let rate=%sysevalf((&k-1)/&k); proc surveyselect data=boottest out=&x. seed=0 samprate=&rate outall rep=10; run; /*開始作10-fold CV*/ data xv&x.; set xv&x.; if selected then new_y=y; run; /*對proc reg內去取得Y的預測值(yhat)*/ proc reg data=xv&x. noprint; model new_y=x; by replicate; output out=outb&x.(where=(new_y=.)) p=yhat; run; /*計算y與yhat的R-square,即這段程式的目標*/ ods output fitstatistics=tt&x.(where=(label2="R-Square")); proc reg data=outb&x. ; model yhat=y; run; %end; %mend boot; %boot; ----------------------------------------------------------------------------- macro初學者,請先進們不吝賜教指點 非常感謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.25.110.97 ※ 編輯: wlsherica 來自: 163.25.110.97 (09/30 11:32) ※ 編輯: wlsherica 來自: 163.25.110.97 (09/30 11:48)
imaltar:把noprint拿掉試試看 09/30 12:14
imaltar:我忘記看到你已經說過拿掉NOPRINT就OK那一行 09/30 12:21
wlsherica:另外想請教因為這樣output跟log file頁數超多 09/30 12:28
wlsherica:是不是可以將他們另存到其他地方,會比較快嗎??? 09/30 12:28
※ 編輯: wlsherica 來自: 163.25.110.97 (09/30 12:35)
kingbee:既然是收析度高的話 hint: ODS 09/30 15:01
wlsherica:謝謝提示!! 09/30 15:22
kingbee:主程式>Tools>Options>system 選單找找看或許比較快 09/30 16:25
kingbee:log視窗是用來看 若太多內容 關掉會比較快 09/30 16:29
kingbee:output的部份 提示 ods trace 及 ods output 的應用 09/30 16:30
kingbee:或是ods select 09/30 16:30
wlsherica:(筆記) 來研究, 謝謝K大與I大 09/30 20:29
maumausam:感謝各位前輩~我也要來學 10/05 01:06