Upload
avice-harris
View
218
Download
4
Embed Size (px)
Citation preview
SAS coding used in creating a routine
report
February 23, 2009February is Heart Month
How it all started…
Create a monthly report that includes:
Tables with accompanying text Graphs with accompanying text Background introduction to the report Table of contents Title page
ODS RTF file=‘pathname/filename.rtf’;{SAS statements}ODS RTF close;
ODS RTF to create the output file
How to…?
Format text Insert special characters Format headers and footers Format a table Insert pictures/graphs Call in an R program from SAS
Stress-busting tip for a healthy heart: Laugh. It’s your body’s natural stress-release mechanism
Basic formats in TITLE TITLE and FOOTNOTE have some basic
formats styles available using keywords: Bold Background/Foreground colour Font sizes Font types Text justification Underlining
TITLE justify=r bold color=blue bcolor=red font=arial height=10 underlin=1 ‘put text here!’;
Format keywords in PROC REPORT Similar to TITLE but some keywords differ
PROC REPORT data=notesstyle(header)=[background=STG foreground=white
just=center font_size=9pt font_face='arial' font_weight=bold];column text;define text / style={foreground=black background=yellow cellwidth=10 cm font_size=11pt font_face='arial'};
run;
ODS ESCAPECHAR Define a special character to indicate RTF
elements Choose a character that is not commonly used in SAS
coding
ODS ESCAPECHAR = ‘^’;{SAS coding}DATA notes;length text $32767;text="^R'{\b\i Put text here! }’ ^R'super\1’ ";run;
Put text here! 1
RTF control words
Control word – specially formatted command that RTF uses to mark printer control codes and information
Control Word Function Control Word Function
\i italicize \cfn foreground colour\line new line \b bold\bullet bullet \ql left align\sub subscript \qr right align\super superscript \qc center align
RTF control symbols and groups
Control symbol – backslash followed by a single, non-alphabetic character Example: \~ for non-breaking space
Groups – text and control words or control symbols between braces, {}
Specify style elements
Specify ODS ESCAPECHAR
Basic form:
^S={style attributes}
^S={indent=0.45cm cellwidth=20cm font_face='arial' font_size=11pt}
Adding text into RTF file
TITLE adds text to top of page FOOTNOTE adds text to bottom of page
How about adding text to the middle of the page or blocks of text? ODS RTF TEXT PROC REPORT
ODS RTF TEXT
Add text before/after a PROCedure
ODS RTF TEXT = “Add text here";
Add formatting using STYLE:
ODS RTF TEXT = "^S={} {Add in text here.}";ODS RTF TEXT = "^S={indent=0.45cm cellwidth=20cm font_face='arial' font_size=11pt}{Add in text here.}";
For larger blocks of text PROC REPORT
Basic PROC REPORT
PROC REPORT data=notes;column text;define text / display;
run;
Adding text using PROC REPORT
ODS ESCAPECHAR=‘^’;ODS RTF file=‘pathname/sample.rtf’;PROC REPORT data=notes noheader center nowd;
column text;define text / width=96 flow style={foreground=black background=white cellwidth=17.75cm font_size=11pt font_face='arial'};
run;ODS RTF close;
Creating text in a DATA step
DATA notes;length text $32767;text=“Insert text here”;run;
DATA notes;length text $32767;text=^S={font_weight=bold font_size=14pt
foreground=STG}^R'\qc' Insert centered bolded text here and add a new line ^n ^S={}"||
"^R'\par\ql' Begin a left justified paragraph. "||“Add in more text and then add 2 lines. ^n^n”;run;
How to…?
Format text Insert special characters Format headers and footers Format a table Insert pictures/graphs Call in an R program from SAS
Healthy-eating for a healthy heart. Choose fresh fruit over juice.
Special Characters
From START menu:
Programs > Accessories > System Tools > Character Map
Copy/Paste symbol into SAS editor
If symbol pastes as ‘?’ then it will not display properly
How to…?
Format text Insert special characters Format headers and footers Format a table Insert pictures/graphs Call in an R program from SAS
A truffle a day lowers blood pressure. Choose chocolate with cocoa content of 70% or higher.
Headers & Footers Format text in TITLE and FOOTNOTE using
keywords (ie. bold, bcolor=, underlin=, font=) or in-line formatting
Insert pictures using PREIMAGE JPG, GIF and PNG
Create sections by using the justification format code
just=center(c), left(l), right(r)
Headers & Footers
FOOTNOTE j=r "^S={font=(‘arial’, 12pt, bold) Insert bold text here.}";
TITLE j=l "^S={preimage='W:\Reports\image1.png'}" j=r "^S={preimage='W:\Report\image2.png'}";
How to…?
Format text Insert special characters Format headers and footers Format a table Insert pictures/graphs Call in an R program from SAS
Stress-busting tip for a healthy heart. Take time for yourself.
Format a table – PROC REPORT
659499999799CHF
948198909798Creatinine Level
969499999399Dialysis
Risk Factors
978058989298Ejection Fraction (EF)5
100111009099100Recommended Urgency4
978596989898Recommended Therapy
99998797100100Lesion Data3
977497989898CAD and/or Valvular Disease
Catheterization Results
10099909996100CCS Angina2
Clinical Status
871009910099100Cardiogenic Shock
871009810099100Hemodynamic Instability
821009910099100CHF
Complicating Factors
97998910099100Fluoroscopy Time
96301009997100Ischemia1
100661009996100ECG (Worst)1
971009810099100Indications
10010099100100100Urgency
98100100100100100Procedure performed
Procedural
248246250237248.Number of Cases
Diagnostic Procedures
Site ESite DSite CSite BSite AHighest
Completion %Data Field
Hospital Completion %
659499999799CHF
948198909798Creatinine Level
969499999399Dialysis
Risk Factors
978058989298Ejection Fraction (EF)5
100111009099100Recommended Urgency4
978596989898Recommended Therapy
99998797100100Lesion Data3
977497989898CAD and/or Valvular Disease
Catheterization Results
10099909996100CCS Angina2
Clinical Status
871009910099100Cardiogenic Shock
871009810099100Hemodynamic Instability
821009910099100CHF
Complicating Factors
97998910099100Fluoroscopy Time
96301009997100Ischemia1
100661009996100ECG (Worst)1
971009810099100Indications
10010099100100100Urgency
98100100100100100Procedure performed
Procedural
248246250237248.Number of Cases
Diagnostic Procedures
Site ESite DSite CSite BSite AHighest
Completion %Data Field
Hospital Completion %
Format rows & columns Add subscripts to text Highlight cells based on a conditional statement
Data setup for formatted table PROC TABULATE, PROC TRANSPOSE and
DATA step to arrange data
Merge with dataset containing: Variable labels (varlabel) to create formatted text in
table (note: RTF control words to format) Categories for grouping variables Variable (npage) to identify where to split table
PROC REPORT tablePROC REPORT data=dproc2 nowd;
column npage category varlabel maxrate ("Hospital Completion %" SiteA SiteB SiteC SiteD SiteE);define npage/ group noprint;define category/ group noprint order=data;define varlabel / display ‘Data Field' center;define maxrate …
run;
Adding formats to PROC REPORTPROC REPORT data=dproc2 nowd center
style(header)=[background=STG foreground=white just=center font_size=9pt font_face='arial' font_weight=bold]style(lines)=[font_size=9pt font_face='arial' just=l font_weight=bold indent=0.2 cm]style(column)=[font_size=9pt font_face='arial' cellwidth=2 cm];…
Formatting specific columns
PROC REPORT data=sample_data nowd center …
define varlabel/ display order=data 'Data Field' left style(column)=[cellwidth=7.3 cm indent=0.9 cm];define maxrate/ display 'Highest Completion %' center style(column)=[foreground=STG font_weight=bold
cellwidth=2.7 cm];run;
Conditional formattingPROC REPORT data=dproc2 nowd center
…
compute varlabel; if varlabel='Number of Cases' then call define(_ROW_, "style","style=[background =PALG font_weight=bold font_style=italic]");endcomp;
%traffic_lighting (SiteA SiteB SiteC SiteD SiteE maxrate, 6);
break after npage/ page;run;
Traffic Lighting%macro traffic_lighting (var, nvar);
%do i=1 %to &nvar;%let rvar=%scan(&var,&i);
compute &rvar;if 0<= &rvar <50 then
call define (_COL_, "STYLE","style=[background=dark red
foreground=white font_weight=bold]");if 50 <= &rvar < 90 then
call define(_COL_, "STYLE","STYLE=[background=gold foreground=black
font_weight=bold]");endcomp;
%end;%mend traffic_lighting;
How to…?
Format text Insert special characters Format headers and footers Format a table Insert pictures/graphs Call in an R program from SAS
Nuts and seeds are high in heart healthy fat. Be sure to reduce other added fats if including nuts and seeds in your diet
Adding in a picture in ODS RTFDATA cover_page; list='^S={preimage="W:\Reports\cover_image.png"}';
PROC REPORT data=cover_page noheader nowdstyle={frame=void};define list /style={cellwidth=21 cm} center;
run;
How to…?
Format text Insert special characters Format headers and footers Format a table Insert pictures/graphs Call in an R program from SAS
Keep active and maintain a healthy weight. Taking the stairs burns 5x as many calories as taking the elevator.
Call an R program from SASOPTIONS XWAIT XSYNC;
DATA _null_;X """C:\Program Files\R\R.exe"" --no-save --quiet < ""W:\graphs2.R"" > ""W:\graphs.log""";infile 'W:\graphs.log';file log;input;put '**R: ' _INFILE_;
run;
Creating the output file
ODS ESCAPECHAR='^';
ODS RTF file=‘filename‘ startpage=no;{Create cover page}ods rtf startpage=now;{Insert background text}…ODS RTF close;
THANKS!