/* APR-proj-K.sas Daniel Brockman 20070523 Graph/ODS project for X405.7 */ /* Fulfilling "Project Requirement - SAS Graphing and Output * Delivery System (ODS) X405.7 by Jianmin Liu, Ph.D. * * 1. A permanent SAS data set will be provided for the project * "for_project". * * 2. Run PROC UNIVARIATE step for variable X1-X5, with ODS * trace on. * * 3. Use PROC PRINT to print out various Tables captured by * ODS. * * 4. Generate HTML format report for PROC UNIVARIATE, PROC * MEANS * * 5. Generate PDF format report for PROC UNIVARIATE, PROC MEANS, * PROC CORR on variables X1-X5 * * 6. USe SAS/GRAPH to generate frequency curves for variable Y1-Y5 * * 7. Use GREPLAY and MACRO PROGRAMMING to generate multiple graphs * one page for variable Y1-Y5 * * 8. (optional) Use Proc G3D to generate 3-D graph of estimated probability of * logistic regression model using the following model specification: * * Log(y/(1-y)) = a1 + a1*X1 + a2*X2 + a3*X3 + a4*X4 * * where y is defined as probability that Y = 1 * * 9. (optional) Use PROC GSLIDE to generate multiple slides in SAS * * 10. Put all together: use SAS MACRO programmming, INCLUDE * statement and AUTOCALL facility to the graphing programs more * portable in a production environment * */ %let dir = C:\b\SAS-X405.7\proj ; * project directory ; %let autocalldir = &dir\subauto ; * autocall dir (Req 10) ; %let outdir = &dir\output ; * output diretory ; %let demotxl = 0 ; * 1=demo var translation 0=otherwise ; %let humstyle = WEB_6 ; * html style type for procs unv & mns; libname odsstore "&dir\odsstore" ; * ODS store ; /* ---------------------------------------------------------------- */ /* for_project data set */ libname mylib "&dir"; * library ; %let forp = for_project ; * input data set; /* req 1 */ /* blood pressure data set */ libname bplib "&dir"; * library ; %let bpset = bpsetdtkg ; * input data set; /* sets to process */ %let APRsets = bplib.&bpset ; * mylib.&forp ; %let nicknames = dbp ; * fp ; /* ---------------------------------------------------------------- */ /* macros in test */ * %include "&autocalldir\grafxy1y2.sas"; * %include "&autocalldir\grafg3d.sas"; /* macros not contained in autocall library (Req 10) */ %include "&dir\APR-sub.sas"; /* macros */ %include "&dir\varform.sas"; /* macros */ %include "&dir\greplay_brockman.sas"; /* macros */ /* options nocenter mlogic mprint symbolgen; */ options ls = 80 /* orientation = landscape */ mprint mlogic symbolgen sasautos="&autocalldir" /* Req 10 */ spool ; /* ---------------------------------------------------------------- */ /* initializations */ %global gvarn gvart gvarnn gvarnc; * global vars used by %vnmtp ; %global greturn ; * global general return var ; /* ---------------------------------------------------------------- */ /* demonstrate use of inline macro (Req 10) */ %macro XvarsODSuni(myset,xchar) ; /* ODS Proc univariate, Changed var names */ /* uses global macro vars gvarn, gvart */ %local vlist ii var; %varform(&myset,xset,&xchar) ; /* set with chgd names is xset */ %vnmtp(xset) ; /* get list of vars */ %let vlist = &gvarnn ; /* list of numeric vars */ %let ii = 0 ; %do %while (%scan(&vlist,&ii+1) ne ) ; %let ii= %eval(&ii + 1); %let var = %scan(&vlist,&ii) ; %put myset:&myset vlist:&vlist ii:&ii var:&var; %uvods(xset,&var); %end ; /* do while */ %mend XvarsODSuni; /* ---------------------------------------------------------------- */ /* inline macro */ %macro body ; /* main process for this program */ %local i j k ; /* aux */ %local is js ks ; /* loop counters */ %local xchar ; /* root name for numbered vars */ %local inp ; /* input data set */ %local Kvarn Kvart Lvarn Lvart ; /* lists of names and types of vars */ %local Kvarnn Kvarnc Lvarnn Lvarnc ; /* names of numeric and char vars */ %local nick ; /* nickname */ %local cnt ; /* aux count */ %local t1 t2 t3 t4 ; /* tempo data set names */ %local gcat ; /* graphic catalog (for %greplay) */ %let xchar = X ; * root name for numbered vars ; goptions reset=all ftext=swiss rotate device=gif ; %let is = 0 ; %do %while (%scan(&APRsets,&is+1," ") ne ) ; /* loop the sets */ %let is = %eval(&is+1); * - - - - - - - - - - - - - - - - - - - - - ; %let inp = %scan(&APRsets,&is," ") ; /* input data set */ %let nick = %scan(&nicknames,&is); /* pickup nickname */ %getdsname(gcat_&nick) ; %let gcat = &greturn ; /* graphic catalog */ * - - - - - - - - - - - - - - - - - - - - - ; %vnmtp(&inp) ; /* get names & types of vars in gvarn gvart */ %let Lvarn=&gvarn; /* names */ %let Lvart=&gvart; /* types */ %let Lvarnn=&gvarnn; /* numerics */ %let Lvarnc=&gvarnc; /* characters */ /* * 6. USe SAS/GRAPH to generate frequency curves for variable Y1-Y5 */ ods html /* make html gallery */ path="&outdir" (url=none) /* output dir */ file="&nick.-gal_body.html" /* main html file */ frame="&nick.-gal_frame.html" /* navigational frame */ contents="&nick.-gal-contents.html" page="&nick.-gal-page.html" gpath="&outdir" /* image files */ ; /* there's no obvious general procedure * so we indulge in custom coding with * separate preparation for blood pressure and forproject */ %if &nick = dbp %then %do ; /* if blood pressure */ %getdsname(&nick) ; %let t1 = &greturn ; /* tempo ds name */ data &t1 ; set &inp ; Kilograms = Wt ; Pulse = Pul; Systolic = Sys; Diastolic = Dia; TimeInDays = Sd; yyyymmdd = Dt; keep Hour Kilograms Systolic Diastolic Pulse TimeInDays yyyymmdd; run; /* now we are working with variables * Hour = Hour of the day * Kilograms = Weight in Round Kilograms * Systolic = Systolic Blood Pressure * Diastolic = Diastolic Blood Pressure * Pulse = Heartbeats per minute * TimeInDays = Time counted in days * yyyymmdd = date of observation */ %vnmtp(&t1) ; /* get names & types of vars in gvarn gvart */ %let Kvarn=&gvarn; /* names */ %let Kvart=&gvart; /* types */ %let Kvarnn=&gvarnn; /* numerics */ %let Kvarnc=&gvarnc; /* characters */ %local grtitle foot ; %let grtitle=Frequencies from Blood Pressure Data ; %let foot =Graph by Daniel Brockman ; %local name ; %let name = graph_ ; /* graph name root */ %let js = 0 ; /* graph name counter */ /* let us now draw charts and graphs */ %let js = %eval(&js+1); %let grtitle=Systolic by Hour and Weight; %grafg3d(&t1,Kilograms,Hour,Systolic, 76,82,9, 4,12,7, 50,130,9, &grtitle,&foot, &name.&js., &gcat ); %let js = %eval(&js+1); %let grtitle=Diastolic by Hour and Weight; %grafg3d(&t1,Kilograms,Hour,Diastolic, 76,82,9, 4,12,7, 50,130,9, &grtitle,&foot, &name.&js., &gcat ); %let js = %eval(&js+1); %let grtitle=Diastolic by Systolic; %graf2a(&t1,Diastolic,Systolic,1,0, &grtitle,&foot, &name.&js., &gcat ); %let js = %eval(&js+1); %let grtitle=Diastolic and Systolic by Pulse; %grafxy1y2(&t1,Pulse,Diastolic,Systolic,1,0, &grtitle,&foot, &name.&js., &gcat ); %let js = %eval(&js+1); %let grtitle=Diastolic and Systolic by Time; %grafxy1y2(&t1,TimeInDays,Diastolic,Systolic,1,0, &grtitle,&foot, &name.&js., &gcat ); %let js = %eval(&js+1); %let grtitle=Diastolic and Systolic by Weight; %grafxy1y2(&t1,Kilograms,Diastolic,Systolic,1,0, &grtitle,&foot, &name.&js., &gcat ); %let js = %eval(&js+1); %let grtitle=Systolic by Time of Day; %graf2a(&t1,Systolic,Hour,1,0, &grtitle,&foot, &name.&js., &gcat ); %let js = %eval(&js+1); %let grtitle=Systolic by Time; %graf2a(&t1,Systolic,TimeInDays,1,0, &grtitle,&foot, &name.&js., &gcat ); /* and now a graphing loop for frequency charts */ %let grtitle=Histogram and Cumulative Frequency; %let ks = 0 ; /* variable name counter */ %do %while (%scan(&Kvarnn,&ks+1) ne ) ; /* loop numeric vars */ %let ks = %eval(&ks+1); %let j = %scan(&Kvarnn,&ks); /* variable name */ /* use ods to make html output of frequencies */ %odshtmlfreq(dsn=&t1,vary=&j,style=WEB_5, file="&outdir\freq-&nick.-&j..html"); /* draw frequency graph */ %let js = %eval(&js+1); /* graph name counter */ %varygraf(dsn=&t1,vary=&j,style=WEB_5, file="&outdir\freq-&nick.-&j..html", title=&grtitle, footnote=&foot, name=&name.&js.,gcat=&gcat) ; %end ; /* do while loop numeric vars */ /* end of graphing loop -- a few more graphs now */ %let js = %eval(&js+1); %let grtitle=Date by Time in Days; %graf2a(&t1,yyyymmdd,TimeInDays,1,0, &grtitle,&foot, &name.&js., &gcat ); %let js = %eval(&js+1); %let grtitle=Systolic by Weight; %graf2a(&t1,Systolic,Kilograms,1,0, &grtitle,&foot, &name.&js., &gcat ); %let js = %eval(&js+1); %let grtitle=Time of Day by Time; %graf2a(&t1,Hour,TimeInDays,1,0, &grtitle,&foot, &name.&js., &gcat ); %let k = -3 ; %do %while(%eval(&k+4) le &js) ; %let k = %eval(&k+4); /* * 7. Use GREPLAY and MACRO PROGRAMMING to generate multiple graphs * one page for variable Y1-Y5 */ /* combo graph */ %greplaybyname( &name.%eval(&k+0), &name.%eval(&k+1), &name.%eval(&k+2), &name.%eval(&k+3), &gcat) ; %end ; /* do while k+4 le js */ title ; footnote ; %end ; /* if blood pressure */ %else %if &nick = fp %then %do ; /* if for project */ %end ; /* if for project */ ods html show; /* does this produce the gifs? */ ods html close; /* finish html gallery */ /* * 2. Run PROC UNIVARIATE step for variable X1-X5, with ODS * trace on. WITHOUT NAME CHANGE. * * 3. Use PROC PRINT to print out various Tables captured by * ODS. */ title "Req 2. Proc Univariate with ODS trace on."; %uvods(&inp,&Lvarnn) ; /* ODS tr on proc univariate */ title "Req 3. Proc Print to print Tables ODS captures."; %prODSuni(&inp,&Lvarnn) ; /* proc print ods tables */ /* * 4. Generate HTML format report for PROC UNIVARIATE, PROC * MEANS */ ods html style=&humstyle file="&outdir\&nick.-mu.html" frame="&outdir\&nick.-mu-frame.html" contents="&outdir\&nick.-mu-table-contents.html" page="&outdir\&nick.-mu-pages-contents.html" ; title "Req 4. HTML format report for Proc Univariate & Proc Means"; %HTML_Uni_Mns(&inp,&Lvarnn,&outdir,&humstyle,odsstore,&nick); ods html close; title ; /* reinit */ /* * 5. Generate PDF format report for PROC UNIVARIATE, PROC MEANS, * PROC CORR on variables X1-X5 */ title "Req 5. Gen PDF for Proc Univariate, Proc Means, Proc Corr" %prODSmuc(dsn=&inp,vlist=&Lvarnn,nick=&nick,odir=&outdir); /* ------------------------------------------ */ %if (&demotxl = 1) %then %do ; /* if do name change */ /* * 2. Run PROC UNIVARIATE step for variable X1-X5, with ODS * trace on. WITH NAME CHANGE. */ /* * note: we consider that retaining the little info of the * original var names helps distinguish the results. So we * demonstrate here that we know how to rename the variables, * for the benefit of the course requirement. Whereas we can * meet the other functional requirements without renaming, * we retain the original variable names for completing the * assignment. See log. */ title "Req 2. Proc Univariate with ODS trace on X1-X5"; %XvarsODSuni(&inp,&xchar) ; /* ODS tr on Proc univariate, Chg var names */ %end ; /* if demotxl */ /* ------------------------------------------ */ %delds(&gcat); /* remove graphics catalog file */ %end; /* end loop the sets */ %mend body; /* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */ %body ; /* Execute this program */ /* ---------------------------------------------------------------- */ ;