PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel...

16
Copyright © SAS Institute Inc. All rights reserved. PROC REPORT og ODS Georg Morsing

Transcript of PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel...

Page 1: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

PROC REPORT og ODSGeorg Morsing

Page 2: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

PROC REPORT og ODS

1. ODS EXCEL Options

2. PROC REPORT kode

3. Style={}

4. TAGATTR

Links til mere information

ODS provides table templates that define the structure of the output from SAS procedures and from the DATA step

A tagset is a collection of events that are triggered in a particular order such as reordering, removing, hiding, and modifying output

Page 3: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

ods excel file='C:\temp\example1.xlsx';

ods excel options(embedded_titles ='yes'

embedded_footnotes ='yes'

tab_color ='blue'

start_at ='2,4'

frozen_headers ='yes');

title 'This title will appear in the worksheet';

footnote 'This footnote will appear in the

worksheet';

proc report data=sashelp.class;

run;

ods excel close;

title;

footnote;

Eksempel 1

Page 4: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

ods excel file='C:\temp\example2.xlsx';

ods excel options(autofilter ='1-3'

absolute_column_width ='15'

absolute_row_height ='25');

proc report data=sashelp.class;

run;

ods excel close;

Eksempel 2

Page 5: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

ods excel file='C:\temp\example3.xlsx';

ods excel options(frozen_headers ='yes'

frozen_rowheaders='yes');

proc report data=sashelp.class;

column sex name age height weight;

define sex / group;

run;

ods excel close;

Eksempel 3

Page 6: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

ods excel file='C:\temp\example4.xlsx'

options(sheet_name ='Class'

sheet_interval='none');

proc sort data=sashelp.class out=class;

by sex;

run;

proc report data=class;

column sex name age height weight;

by sex;

run;

ods excel close;

Eksempel 4

Page 7: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

ods excel file='C:\temp\example4B.xlsx'

options(sheet_interval='bygroup');

proc sort data=sashelp.class out=class;

by sex;

run;

proc report data=class;

column sex name age height weight;

by sex;

run;

ods excel close;

Eksempel 4B

Page 8: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

ods excel file='C:\temp\example5.xlsx'

options(sheet_interval='none'

sheet_name ='Age');

proc report data=sashelp.class;

column age height weight;

define age / group;

define height / mean;

rbreak before / summarize;

run;

ods excel options(sheet_interval="output");

ods exclude all;

data _null_;

declare odsout obj();

run;

ods select all;

ods excel options(sheet_interval='none'

sheet_name ='Sex');

proc report data=sashelp.class;

column sex height weight;

define sex / group;

define height / mean;

rbreak before / summarize;

run;

ods excel close;

Eksempel 5

Page 9: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

ods excel file='C:\temp\example5.xlsx'

options(sheet_interval='none'

sheet_name ='Age');

proc report data=sashelp.class;

column age height weight;

define age / group;

define height / mean;

rbreak before / summarize;

run;

ods excel options(sheet_interval="output");

ods exclude all;

data _null_;

declare odsout obj();

run;

ods select all;

ods excel options(sheet_interval='none'

sheet_name ='Sex');

proc report data=sashelp.class;

column sex height weight;

define sex / group;

define height / mean;

rbreak before / summarize;

run;

ods excel close;

Eksempel 5

Data Step ODS Interface

This tells the data step compiler that a

variable obj is of class

type odsout, and all necessary ODS

initialization is performed.

Re-initialization of the ODS excel

destination.

Page 10: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

Eksempel 6

proc report data=pricedata

style(summary)=[font_weight=bold];

define price / style(column)=[tagattr="format:$#,###.00;$-#,###.00"];

define cost / style(column)=[tagattr="format:$#,###;$-#,###"];

define sale / style(column)=[tagattr="format:#,###"];

compute before regionname /style=[background=lightblue

just=l

ont_weight=bold];

line regionname $20.;

endcomp;

Page 11: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

Eksempel 6

proc report data=pricedata

style(summary)=[font_weight=bold];

define price / style(column)=[tagattr="format:$#,###.00;$-#,###.00"];

define cost / style(column)=[tagattr="format:$#,###;$-#,###"];

define sale / style(column)=[tagattr="format:#,###"];

compute before regionname /style=[background=lightblue

just=l

ont_weight=bold];

line regionname $20.;

endcomp;

https://support.sas.com/resources/papers/proceedings11/250-2011.pdf

Page 12: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

Eksempel 6

*change the text for productname on summary row;

*add borders to the whole row;

*add a blank line after each section;

compute after regionname;

productname = catx(' ','Total',regionname);

if _break_ ^= '' then

call define(_row_,'style',

'style=[bordertopstyle=solid

bordertopwidth=1pt

bordertopcolor=black

borderbottomstyle=solid

borderbottomwidth=1pt

borderbottomcolor=black]');

line ' ';

endcomp;

Page 13: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

Eksempel 6 *apply coloring based on target values;

*add formulas to summary rows;

compute sale;

if _break_ = '' then

do;

if sale.sum < 20000 then

call define(_col_,'style','style=[background=red]');

else if sale.sum > 30000 then

call define(_col_,'style',style=[background=green]');

end;

endcomp;

Page 14: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

Eksempel 6 *add formulas to summary rows;

compute sale;

if upcase(_break_) = 'REGIONNAME' then

do;

if region = 1 then call define('sale.sum','style',

'style=[tagattr="formula:sum(E5:E7) format:#,###"]');

else if region = 2 then call define('sale.sum','style',

'style=[tagattr="formula:sum(E11:E18) format:#,###"]');

else if region = 3 then call define('sale.sum','style',

'style=[tagattr="formula:sum(E22:E27) format:#,###"]');

end;

else if _break_ = '_RBREAK_' then

do;

call define('sale.sum','style',

'style=[tagattr="formula:sum(E8,E19,E28) format:#,###"]');

end;

endcomp;

Page 15: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

PROC REPORT og ODS

PROC REPORT Output Delivery System

Bøger om SAS https://www.sas.com/store/books

Page 16: PROC REPORT og ODS - SAS · PROC REPORT og ODS 1. ODS EXCEL Options 2. ... ods excel file='C:\temp\example5.xlsx' options ... column sex height weight;

Copyright © SAS Inst itute Inc. A l l r ights reserved.

PROC REPORT og ODS

• http://support.sas.com/resources/papers/proceedings17/SAS0235-2017.pdf

• http://support.sas.com/resources/papers/proceedings17/SAS0127-2017.pdf

• https://support.sas.com/resources/papers/proceedings11/250-2011

• http://support.sas.com/resources/papers/tnote/tnote_base.html