33
SAS coding used in creating a routine report February 23, 2009 February is Heart Month

SAS coding used in creating a routine report February 23, 2009 February is Heart Month

Embed Size (px)

Citation preview

Page 1: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

SAS coding used in creating a routine

report

February 23, 2009February is Heart Month

Page 2: SAS coding used in creating a routine report February 23, 2009 February 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

Page 3: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

ODS RTF file=‘pathname/filename.rtf’;{SAS statements}ODS RTF close;

ODS RTF to create the output file

Page 4: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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

Page 5: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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!’;

Page 6: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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;

Page 7: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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

Page 8: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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

Page 9: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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, {}

Page 10: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

Specify style elements

Specify ODS ESCAPECHAR

Basic form:

^S={style attributes}

^S={indent=0.45cm cellwidth=20cm font_face='arial' font_size=11pt}

Page 11: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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

Page 12: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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.}";

Page 13: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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;

Page 14: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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;

Page 15: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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.

Page 16: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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

Page 17: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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.

Page 18: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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)

Page 19: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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'}";

Page 20: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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.

Page 21: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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

Page 22: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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

Page 23: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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;

Page 24: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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];…

mkl
WHAT IS LINE? IS IT A ROW?
Page 25: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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;

Page 26: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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;

Page 27: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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;

Page 28: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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

Page 29: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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;

Page 30: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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.

Page 31: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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;

Page 32: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

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;

Page 33: SAS coding used in creating a routine report February 23, 2009 February is Heart Month

THANKS!