ybao
ybao

Reputation: 147

Line graph of frequency vs age of onset for multiple diseases in SAS

I have a set of patient data with age of onset of diseases and I would like to plot the frequency of each disease's age of onset with a different line. The x axis would be age of onset and y axis would be frequency, with each line representing a different disease. The 0 in age indicates the patient does not have that disease. What would be code be in SAS to do this? Thanks so much!

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

Upvotes: 0

Views: 101

Answers (1)

kl78
kl78

Reputation: 1666

Not 100% sure if i understood your problem correct, but i tried to provide a solution.

This is maybe a complicated solution, i guess there are much short/easier solutions. I count the freqs for each disease, merge them to one dataset and draw them with a 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;                                                                                                                                    

With the sample data this would lead to this graph, i guess with real data this will look better because now we have no age more then once for each disease:

enter image description here

As simple alternative you could use a Proc freq dotplot, but then you have seperated graphs and only dots, as far as i understood you wanted output like in the long solution:

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

Upvotes: 0

Related Questions