Printing Data and Exporting Reports in SAS – PROC PRINT and ODS
Welcome back to Mindful Data Minds! In this session, we’ll learn how to print datasets using PROC PRINT and how to export reports in different formats (HTML, PDF) using the Output Delivery System (ODS).
Watch the Full Tutorial
What You Will Learn
- How to use PROC PRINT to display datasets.
- How to select specific columns and customize observation numbers.
- How to add titles and footnotes.
- How to export reports to HTML and PDF using ODS.
- How to apply labels for cleaner report presentation.
Printing Data with PROC PRINT
PROC PRINT is the simplest way to display data in SAS.
proc print data=sashelp.cars;
run;
This prints all rows and columns from the dataset SASHELP.CARS, along with observation numbers.
Selecting Specific Columns
If you only want certain variables (e.g., Make and Model):
proc print data=sashelp.cars;
var make model;
run;
Prints only the Make and Model columns.
Customizing Observation Numbers
By default, SAS shows an OBS column. You can customize or remove it:
- Change OBS label:
proc print data=sashelp.cars obs="Serial No.";
var make model;
run;
- Remove OBS completely:
proc print data=sashelp.cars noobs;
var make model;
run;
Limiting Records
To print only the first 10 observations:
proc print data=sashelp.cars(obs=10);
var make model;
run;
Adding Titles and Footnotes
You can add headings and footers to your report:
title "First 10 Records of SASHELP.CARS";
footnote "Prepared by XXX";
proc print data=sashelp.cars(obs=10);
var make model;
run;
Titles appear at the top, footnotes at the bottom.
Exporting Reports with ODS
The Output Delivery System (ODS) lets you save reports in formats like HTML or PDF.
Export to HTML
ods html file="C:\tutorial\html_test.html";
proc print data=sashelp.cars(obs=10);
var make model;
run;
ods html close;
Creates an HTML file with the report.
Export to PDF
ods pdf file="C:\tutorial\pdf_test.pdf";
proc print data=sashelp.cars(obs=10);
var make model;
run;
ods pdf close;
Creates a PDF file with the report.
Using Labels
You can rename variables for reporting without changing the dataset:
proc print data=sashelp.cars(obs=10) label;
var make model;
label make="Car Make" model="Car Model";
run;
Output shows “Car Make” and “Car Model” instead of the original names.
Next Step
Continue learning by exploring the next tutorial in this series. Also subscribe to get notified about new lessons.
Have a Question?
Drop your doubts in the comments below or contact us.
