2014-09-20 637 views
1

我在sas中編寫了下面的代碼,但是我沒有得到結果!在SAS中繪製直方圖和箱線圖

灰色結果直方圖和數據範圍不像我指定的那樣!問題是什麼?

我得到以下警告過:警告:中點=名單擴展以適應數據

什麼顏色?

axis1 order=(0 to 100000 by 50000); 
axis2 order=(0 to 100 by 5); 
run; 
proc capability data=HW2 noprint; 
histogram Mvisits/midpoints=0 to 98000 by 10000 
haxis=axis1 
cfill=blue; 
run; 

enter image description here .......................................

我有同樣的問題boxplot,例如我得到了以下情節,我想改變的距離,然後我可以看到更好的情節,但我不能。

enter image description here

+1

你有非常大的數值,這使得兩條曲線無用的,如果你有興趣的可視化數據在典型值附近的分佈(例如,在直方圖的情況下爲0-3000)。無論如何,這個問題是無關緊要的,因爲它是關於SAS編程的。 – chl 2014-09-20 19:02:00

+0

[繪製SAS中的直方圖]的可能的副本(http://stackoverflow.com/questions/25944250/drawing-histogram-in-sas) – 2014-09-20 19:12:29

回答

2

下面是proc univariate而非proc capability,我沒有獲得SAS/QC測試,但用戶指南顯示直方圖語句很相似的語法。希望你能翻譯回來。

看起來您由於輸出系統而出現顏色問題。您的圖表可能通過ODS提供,在這種情況下,cfill選項不適用(請參閱here而不是傳統圖形標籤)。

要更改ODS輸出的柱狀圖的顏色,您可以使用proc template

proc template; 
    define style styles.testStyle; 
     parent = styles.htmlblue; 
     style GraphDataDefault/
      color = green; 
    end; 
run; 

ods listing style = styles.testStyle; 

proc univariate data = sashelp.cars; 
    histogram mpg_city; 
run; 

一個例子解釋這個可以發現here

或者您可以使用proc sgplot創建具有顏色的更多控制的柱狀圖如下:

proc sgplot data = sashelp.cars; 
    histogram mpg_city/fillattrs = (color = red); 
run; 

至於你截斷直方圖的問題。忽略極端值並不是很有意義,因爲它會給你一個錯誤的分佈圖像,這有點失敗了直方圖的目的。這就是說,你可以達到你所要求的與一個黑客位:

data tempData; 
    set sashelp.cars; 
    tempClass = 1; 
run; 

proc univariate data = tempData noprint; 
    class tempClass; 
    histogram mpg_city/maxnbin = 5 endpoints = 0 to 25 by 5; 
run; 

在一個虛擬的類tempClass上面創建,然後使用class聲明要求比較直方圖。 maxnbins將限制僅在比較直方圖中顯示的垃圾箱數量。

您的其他選擇是在創建直方圖之前排除(或限制)您的極值點,但這會導致略微錯誤的頻率計數/百分比/酒吧高度。

data tempData; 
    set sashelp.cars; 
    mpg_city = min(mpg_city, 20); 
run; 

proc univariate data = tempData noprint; 
    histogram mpg_city/endpoints = 0 to 25 by 5; 
run; 

這是一個可行的方法,以原來的問題(未經測試,因爲沒有SAS/QC或數據):

proc capability data = HW2 noprint; 
    histogram Mvisits/
     midpoints = 0 to 300000 by 10000 
     noplot 
     outhistogram = histData; 
run; 
proc sgplot data = histData; 
    vbar _MIDPT_/
     response = _OBSPCT_ 
     fillattrs = (color = blue); 
    where _MIDPT_ <= 100000; 
run; 
+0

感謝您的回答:)順便說一句,我怎樣才能更改我的代碼,使boxplot變得更清晰了?或者由於數據分佈,boxplot非常不正常! – 2014-09-21 03:53:13

+0

我建議你轉到文檔以瞭解直方圖語句,也許還要閱讀ODS和proc sgplot,瞭解系統如何工作可能會爲您節省時間。也就是說,我在上面添加了一個可能的方法;因爲我沒有SAS/QC或您的數據沒有經過測試。 – SRSwift 2014-09-21 17:14:32