2016-06-14 99 views
0

我有一組患者的疾病發病年齡數據,我想用不同的線繪出每種疾病發病年齡的頻率。 x軸是發病年齡,y軸是頻率,每條線代表不同的疾病。年齡0表示患者沒有該疾病。 SAS中的代碼是做什麼的?非常感謝!SAS中多種疾病的頻率與發病年齡的關係曲線圖

HoHTAge HoGDAge AddDAge CelDAge 
0 0 32 0 
0 0 0 0 
12 0 23 0 
0 20 0 0 
25 0 0 0 
0 0 0 0 
32 0 0 0 
0 0 0 0 
0 0 0 0 
0 0 0 0 
0 0 0 0 
0 0 0 35 
45 0 0 0 
0 0 0 0 
0 0 0 0 
43 0 0 0 
0 23 0 0 
0 18 0 0 
0 0 0 0 
0 0 0 0 
0 0 0 0 
0 12 0 0 
30 26 0 0 
0 40 46 0 
0 0 0 30 
57 0 0 0 
0 0 0 0 
+0

你有沒有試過一些代碼,它做了什麼? – vielmetti

+0

你是在一個變量或變量之內計算出的頻率?所以如果32在列1中出現一次,在列3中出現一次,列1的頻率是1 /(列1中的obs的數量)還是1 /(列1和3中的obs的數量)? – superfluous

+0

對於freqplot,你可以在每個年齡的單個(點)情節中做到這一點,但據我瞭解,你希望所有年齡的頻率在一個情節中作爲一條線?包括0還是排除之前?一種方法是在Sperate步驟中構建圖的數據,然後使用gplot。 – kl78

回答

0

不是100%確定如果我明白你的問題是正確的,但我試圖提供一個解決方案。

這可能是一個複雜的解決方案,我想有很多簡單/簡單的解決方案。我算每種疾病的freqs,它們合併到一個數據集,並用gplot吸引他們:

data x; 
input HoHTAge HoGDAge AddDAge CelDAge; 
datalines; 
0 0 32 0 
0 0 0 0 
12 0 23 0 
0 20 0 0 
25 0 0 0 
0 0 0 0 
32 0 0 0 
0 0 0 0 
0 0 0 0 
0 0 0 0 
0 0 0 0 
0 0 0 35 
45 0 0 0 
0 0 0 0 
0 0 0 0 
43 0 0 0 
0 23 0 0 
0 18 0 0 
0 0 0 0 
0 0 0 0 
0 0 0 0 
0 12 0 0 
30 26 0 0 
0 40 46 0 
0 0 0 30 
57 0 0 0 
0 0 0 0 
; 
run; 

proc freq data=x noprint ; 
tables HoHTAge/out=a; 

run; 
proc freq data=x noprint ; 
tables HoGDAge/out=b; 

run; 
proc freq data=x noprint ; 
tables AddDAge/out=c; 

run; 
proc freq data=x noprint ; 
tables CelDAge/out=d; 

run; 

data res (drop =percent count); 
merge a (in=a rename=(HoHTAge=age)) b (in=b rename=(HoGDAge=age)) c (in=c rename=(AddDAge=age)) d(in=d rename=(CelDAge=age)); 
by age; 
*if age=0 then count=0; /*if you want to exclude age 0*/ 
if a then HoHTAge=count; else HoHTAge=0; 
if b then HoGDAge=count; else HoGDAge=0; 
if c then AddDAge=count; else AddDAge=0; 
if d then CelDAge=count; else CelDAge=0; 

ruN; 
/* Set the graphics environment */                          
goptions reset=all cback=white border htext=10pt htitle=12pt; 

axis1 label=("age");               
axis2 label=("Count");                      

symbol1 interpol=join color=R height=14pt font='Arial' ;               
symbol2 interpol=join color=B height=14pt font='Arial';              
symbol3 interpol=join color=O height=14pt font='Arial' ;               
symbol4 interpol=join color=BL height=14pt font='Arial' ;                                                          
legend1 repeat=1 label=none frame;                     

proc gplot data=res;                            
    plot (HoHTAge HoGDAge AddDAge CelDAge)*age/ overlay legend=legend1 haxis=axis1 vaxis=axis2;                   
run;                                  

與樣本數據,這將導致這個圖,我想用真實的數據,這將更好看,因爲現在我們有沒有年齡,曾多次針對每種疾病:

enter image description here

作爲簡單的選擇,你可以使用一個Proc頻率點陣圖,但你必須分隔的圖表,只有點,據我瞭解,你想輸出的像長期解決方案:

ods graphics on; 
proc freq data=x ; 
tables HoHTAge HoGDAge AddDAge CelDAge/plots=freqplot(type=dot ORIENT = VERTICAL); 
run; 
+0

謝謝!太棒了! – ybao