9.4 Generating CSV, PowerPoint & Other ODS Destinations
Key Takeaways
The content guide requires HTML, PDF, RTF, XLSX, and PPTX files plus comma-separated value files from ODS statements.
ODS CSV writes procedure output as comma-separated text; ODS CSVALL adds titles, footnotes, and by-line rows that ODS CSV omits.
ODS POWERPOINT produces a native .pptx deck in which each procedure output becomes a slide, and LAYOUT= controls the slide template.
STYLE= applies a style template on any destination opening statement, and STARTPAGE= controls where new pages or slides begin.
ODS CSV is a reporting destination while PROC EXPORT is a data-transfer utility, so ODS CSV honours formats, labels, and titles that PROC EXPORT ignores.
9.4 Generating CSV, PowerPoint & Other ODS Destinations
Quick Answer: The content guide's ODS objective asks for four things: identify the Output Delivery System destinations, create HTML, PDF, RTF, XLSX, and PPTX files with ODS statements, use the
STYLE=option to specify a style template, and generate comma-separated value (CSV) files with ODS statements. HTML, PDF, RTF, and XLSX are covered in the preceding sections; this section closes out CSV and PPTX and the options that apply across every destination.
1. ODS CSV: Procedure Output as Comma-Separated Text
ods csv file="C:\reports\region_summary.csv";
proc means data=sashelp.shoes mean sum maxdec=2;
class Region;
var Sales;
run;
ods csv close;
ODS CSV takes the rendered report — the same table PROC MEANS would print — and writes it as comma-separated text. Because it is a reporting destination rather than a data-transfer utility, it honours everything the report honours: column labels, applied formats, computed statistic columns, and the column order the procedure chose.
ODS CSV versus ODS CSVALL
| Destination | What it writes |
|---|---|
ODS CSV | The table only — the column headings row plus data rows |
ODS CSVALL | The table plus titles, footnotes, by-lines, and blank separator rows |
ods csvall file="C:\reports\annotated_summary.csv";
title "Regional Sales Summary";
footnote "Source: SASHELP.SHOES";
proc means data=sashelp.shoes mean sum maxdec=2;
class Region;
var Sales;
run;
ods csvall close;
footnote;
Use CSV when another program will parse the file, because leading title rows break most parsers. Use CSVALL when a human will open it and needs the context.
Two Ways to Get a CSV, and When Each Is Right
| Requirement | Correct tool |
|---|---|
| A CSV of a procedure's report, with labels, formats, and computed statistics | ODS CSV |
| A CSV of a data set's raw rows, one row per observation | PROC EXPORT ... DBMS=CSV |
| A CSV whose exact layout you control line by line | DATA _NULL_ with FILE and PUT |
Exam Trap:
ODS CSVwrites what the procedure displayed. Point it at aPROC MEANSstep and you get the summary statistics, not the underlying observations. When a question asks for a comma-delimited copy of a data set,PROC EXPORTis the answer; when it asks for a comma-delimited copy of a report,ODS CSVis.
2. ODS POWERPOINT: Native .pptx Decks
ods powerpoint file="C:\reports\quarterly_review.pptx"
style=PowerPointLight;
title "Q1 Sales by Region";
proc means data=sashelp.shoes mean sum maxdec=2;
class Region;
var Sales;
run;
title "Q1 Product Mix";
proc freq data=sashelp.shoes;
tables Product / nocum;
run;
ods powerpoint close;
Each procedure output becomes a slide, with the active TITLE used as the slide title. The result is a genuine OpenXML .pptx file that opens natively in PowerPoint — no image capture, no manual pasting.
Controlling Slide Layout
ods powerpoint file="C:\reports\deck.pptx"
layout=titleandcontent
style=PowerPointDark;
LAYOUT= value | Slide template produced |
|---|---|
TITLEANDCONTENT (default) | Title bar plus a single content region |
TITLEONLY | Title bar only, useful for section dividers |
CONTENT | Content region with no title bar |
TWOCONTENT | Two side-by-side content regions |
STARTPAGE= behaves on ODS POWERPOINT the way it does on ODS PDF: STARTPAGE=NO keeps consecutive procedure outputs on the same slide, and STARTPAGE=NOW forces a break immediately.
ods powerpoint file="C:\reports\compact.pptx" startpage=no;
proc print data=sashelp.class(obs=5) noobs; run;
proc means data=sashelp.class mean; var Height; run; /* same slide */
ods powerpoint close;
3. Style Templates Apply Everywhere
STYLE= is accepted on the opening statement of essentially every destination, so one option controls fonts, colours, borders, and cell padding across the whole document.
ods pdf file="report.pdf" style=Pearl;
ods rtf file="report.rtf" style=Journal;
ods excel file="report.xlsx" style=Excel;
ods powerpoint file="report.pptx" style=PowerPointDark;
ods csv file="report.csv"; /* CSV is plain text - STYLE= has no visual effect */
ODS CSV accepts the option without complaint but produces plain text, so a style template has nothing to act on. That asymmetry is a favourite distractor.
4. Opening Several Destinations at Once
ODS routes each output object to every open destination simultaneously. One execution of a procedure can therefore populate four files.
ods listing close; /* skip redundant text rendering */
ods pdf file="C:\out\summary.pdf" style=Pearl;
ods excel file="C:\out\summary.xlsx" style=Excel;
ods powerpoint file="C:\out\summary.pptx" style=PowerPointLight;
ods csv file="C:\out\summary.csv";
title "Regional Sales Summary";
proc means data=sashelp.shoes mean sum maxdec=2;
class Region;
var Sales;
run;
ods _all_ close; /* closes every open destination in one statement */
ods listing; /* restore the default for interactive work */
ODS _ALL_ CLOSE; is the safety net at the end of a batch program: it releases every file lock without your having to remember which destinations were opened.
5. Destination Summary
| Destination | File produced | Honours styles? | Typical use |
|---|---|---|---|
ODS HTML | .html | Yes | Web and screen viewing |
ODS PDF | .pdf | Yes | Printing, archiving, distribution |
ODS RTF | .rtf | Yes | Editable Microsoft Word documents |
ODS EXCEL | .xlsx | Yes | Formatted multi-tab spreadsheets |
ODS POWERPOINT | .pptx | Yes | Slide decks, one slide per output object |
ODS CSV / CSVALL | .csv | No | Machine-readable comma-delimited report text |
ODS LISTING | Text | No | Legacy monospaced output |
ODS OUTPUT | SAS data set | n/a | Capturing any output object as data |
Which ODS destination writes procedure output as comma-separated text including the titles and footnotes?
ODS CSV
ODS CSVALL
ODS LISTING
ODS EXCEL with DBMS=CSV
A programmer must deliver a native PowerPoint file in which each procedure's output appears on its own slide. Which statement opens the correct destination?
ods pptx file="deck.pptx";
ods powerpoint file="deck.pptx";
ods html file="deck.pptx" type=slides;
ods presentation file="deck.pptx";
A request asks for a comma-delimited file containing every observation of WORK.CUSTOMERS, one row per customer. Which tool is correct and why?
ODS CSV, because it always writes the underlying observations of the data set named in DATA=
PROC EXPORT with DBMS=CSV, because ODS CSV writes what a procedure displayed rather than the raw rows
ODS CSVALL, because only CSVALL includes data rows
ODS LISTING redirected to a .csv file
What does ODS _ALL_ CLOSE; accomplish at the end of a batch program?
It deletes every output file that was created during the session
It closes every currently open ODS destination, releasing the file locks
It closes only the LISTING destination and leaves the others open
It merges all open destinations into a single output file
Sections you finish are checked off in the contents.