/* varygraf.sas Daniel Brockman 070515 Frequency graphing */ /* -------------------------------------------------------------- */ %macro varygraf(dsn=,vary=,style=WEB_7,file=, title=,footnote=,name=,gcat=) ; /* * dsn input data set * vary name of a variable of dsn to graph * style SAS HTML style (function disabled) * file name of HTML file to write (function disabled) * title A title for the chart * footnote A footnote for the chart * name name to attach to chart (see name plot option of proc gplot) * gcat Output graphic catalog (gout) * * %varygraf uses proc freq to calculate the frequencies * proc gplot to draw a chart of the frequencies * and cumulative frequencies. * * Choose the name of gcat as you would a dataset name. */ %global greturn; %local t1 t2 i j k; *ods html style=&style file=&file ; * get temporary set names ; %getdsname(dsn); %let t1 = &greturn; %getdsname(dsn); %let t2 = &greturn; data &t2 ; set &dsn ; if &vary ; run ; * remove missing obs ; proc sort data=&t2 ; by &vary ; run ; * sort input ; proc freq data=&t2 order=data noprint ; * compute frequencies ; tables &vary / cumcol out=&t1 ; * output frequencies ; run; data &t2 ; set &t1 ; retain cumpct ; if _N_ = 1 then cumpct = percent ; else cumpct = percent + cumpct ; * calc cum pct ; run ; * proc print data=&t2 ; * display frequencies; * run; * goptions ftext=swiss gsfmode=append rotate gprolog='%!' display ; * goptions device=gif; title h=2 "&title"; footnote h=1 "&footnote"; proc gplot data=&t2 gout=&gcat; symbol1 i=join h=1; symbol2 i=join h=1; plot Percent*&vary cumpct*&vary / overlay name="&name." ; run; *ods html close; title ; footnote ; * reinit ; * remove tempo datasets; %delds(&t1); %delds(&t2); %mend varygraf ; /* -------------------------------------------------------------- */