Procedure features:
PROC PRINT statement options:
DOUBLE
STYLE
VAR statement
Other Features:
ODS HTML statement
This example
selects three variables for the report
uses variable labels as column headings
double spaces between rows of the report.
Set the SAS system options.
options nodate pageno=1 linesize=70 pagesize=60;
Create the input data set. EXPREV contains information about a company s monthly expenses and revenues for two regions of the United States.
data exprev; input Region $ State $ Month monyy5. Expenses Revenues; format month monyy5.; datalines; Southern GA JAN95 2000 8000 Southern GA FEB95 1200 6000 Southern FL FEB95 8500 11000 Northern NY FEB95 3000 4000 Northern NY MAR95 6000 5000 Southern FL MAR95 9800 13500 Northern MA MAR95 1500 1000 ;
Print the data set EXPREV. DOUBLE inserts a blank line between observations. (This option has no effect on the HTML output.)
proc print data=exprev double;
Select the variables to include in the report. The VAR statement creates columns for Month, State, and Expenses, in that order.
var month state expenses;
Specify a title. The TITLE statement specifies a title for the report.
title 'Monthly Expenses for Offices in Each State'; run;
By default, PROC PRINT identifies each observation by number under the column heading Obs.
Monthly Expenses for Offices in Each State 1 Obs Month State Expenses 1 JAN95 GA 2000 2 FEB95 GA 1200 3 FEB95 FL 8500 4 FEB95 NY 3000 5 MAR95 NY 6000 6 MAR95 FL 9800 7 MAR95 MA 1500
You can easily create HTML output by adding ODS statements. In the following example, ODS statements were added to produce HTML output.
options nodate pageno=1 linesize=70 pagesize=60;
Create HTML output and specify the file to store the output in. The ODS HTML statement opens the HTML destination. FILE= specifies the external file that you want to contain the HTML output.
ods html file= ' your_file.html '; proc print data=exprev double; var month state expenses; title 'Monthly Expenses for Offices in Each State'; run;
Close the HTML destination. The ODS HTML CLOSE statement closes the HTML destination.
ods html close;
You can go a step further and add more formatting to your HTML output. The following example uses the STYLE option to add shading to your HTML report.
options nodate pageno=1 linesize=70 pagesize=60; ods html file= ' your_file.html ';
Create stylized HTML output. The first STYLE option specifies that the column headers be written in white italic font.
The second STYLE option specifies that SAS change the color of the background of the observations column to red.
Proc Print data=exprev double style(HEADER) = {font_style=italic foreground = white} style(OBS) = {background=red}; var month state expenses; title 'Monthly Expenses for Offices in Each State'; run;
Close the HTML destination. The ODS HTML CLOSE statement closes the HTML destination.
ods html close;
Procedure features:
PROC PRINT statement options:
N
OBS=
SPLIT=
STYLE
VAR statement option:
STYLE
Other features:
LABEL statement
ODS PDF statement
Data set: EXPREV on page 739
This example
customizes and underlines the text in column headings for variables
customizes the column header for the column that identifies observations by number
shows the number of observations in the report
writes the values of Expenses with commas.
options nodate pageno=1 linesize=70 pagesize=60;
Print the report and define the column headings. SPLIT= identifies the asterisk as the character that starts a new line in column headers. The N option prints the number of observations at the end of the report. OBS= specifies the column header for the column that identifies each observation by number. The split character (*) starts a new line in the column heading. Therefore, the equal signs (=) in the value of OBS= underline the column header.
proc print data=exprev split='*' n obs='Observation*Number*===========';
Select the variables to include in the report. The VAR statement creates columns for Month, State, and Expenses, in that order.
var month state expenses;
Assign the variables labels as column headings. The LABEL statement associates a label with each variable for the duration of the PROC PRINT step. When you use SPLIT= in the PROC PRINT statement, the procedure uses labels for column headers. The split character (*) starts a new line in the column heading. Therefore, the equal signs (=) in the labels underline the column headers.
label month='Month**=====' state='State**=====' expenses='Expenses**========';
Specify a title for the report, and format any variable containing numbers . The FORMAT statement assigns a format to use for Expenses in the report. The TITLE statement specifies a title.
format expenses comma10.; title 'Monthly Expenses for Offices in Each State'; run;
Monthly Expenses for Offices in Each State 1 Observation Month State Expenses Number =========== ===== ===== ======== 1 JAN95 GA 2,000 2 FEB95 GA 1,200 3 FEB95 FL 8,500 4 FEB95 NY 3,000 5 MAR95 NY 6,000 6 MAR95 FL 9,800 7 MAR95 MA 1,500 N=7
You can easily create PDF output by adding a few ODS statements. In the following example, ODS statements were added to produce PDF output.
options nodate pageno=1 linesize=70 pagesize=60;
Create PDF output and specify the file to store the output in. The ODS PDF statement opens the PDF destination and creates PDF output. The FILE= argument specifies your external file that contains the PDF output.
ods pdf file= ' your_file.pdf '; proc print data=exprev split='*' n obs='Observation*Number*==========='; var month state expenses; label month='Month**=====' state='State**=====' expenses='Expenses**========'; format expenses comma10.; title 'Monthly Expenses for Offices in Each State'; run;
Close the PDF destination. The ODS PDF CLOSE statement closes the PDF destination.
ods pdf close;
options nodate pageno=1 linesize=70 pagesize=60; ods pdf file= ' your_file.pdf ';
Create stylized PDF output. The first STYLE option specifies that the background color of the cell containing the value for N be changed to blue and that the font style be changed to italic. The second STYLE option specifies that the background color of the observation column, the observation header, and the other variable's headers be changed to white.
proc print data=exprev split='*' n obs='Observation*Number*===========' style(N) = {font_style=italic background= blue} Style(HEADER OBS OBSHEADER) = {background=white};
Create stylized PDF output. The STYLE option changes the color of the cells containing data to gray.
var month state expenses / style (DATA)= [ background = gray ] ; label month='Month**===== state='State**=====' expenses='Expenses**========'; format expenses comma10.; title 'Monthly Expenses for Offices in Each State'; run;
Close the PDF destination. The ODS PDF CLOSE statement closes the PDF destination.
ods pdf close;
Procedure features:
PROC PRINT statement options:
LABEL
N=
NOOBS
STYLE
BY statement
PAGEBY statement
Other features:
SORT procedure
LABEL statement
ODS RTF statement
Data set: EXPREV on page 739
This example
suppresses the printing of observation numbers at the beginning of each row
presents the data for each state in a separate section of the report
begins a new page for each region.
options pagesize=60 pageno=1 nodate linesize=70;
Sort the EXPREV data set. PROC SORT sorts the observations by Region, State, and Month.
proc sort data=exprev; by region state month; run;
Print the report, specify the total number of observations in each BY group , and suppress the printing of observation numbers. N= prints the number of observations in a BY group at the end of that BY group. The explanatory text that the N= option provides precedes the number. NOOBS suppresses the printing of observation numbers at the beginning of the rows. LABEL uses variables labels as column headings.
proc print data=exprev n='Number of observations for the state: ' noobs label;
Specify the variables to include in the report. The VAR statement creates columns for Month, Expenses, and Revenues, in that order.
var month expenses revenues;
Create a separate section for each region of the state and specify page breaks for each BY group of Region. The BY statement produces a separate section of the report for each BY group and prints a heading above each one. The PAGEBY statement starts a new page each time the value of Region changes.
by region state; pageby region;
Establish the column headings. The LABEL statement associates a label with the variable Region for the duration of the PROC PRINT step. When you use the LABEL option in the PROC PRINT statement, the procedure uses labels for column headings.
label region='Sales Region';
Format the columns that contain numbers and specify a title. The FORMAT statement assigns a format to Expenses and Revenues for this report. The TITLE statement specifies a title.
format revenues expenses comma10.; title 'Sales Figures Grouped by Region and State'; run;
Sales Figures Grouped by Region and State 1 ------------------- Sales Region=Northern State=MA ------------------- Month Expenses Revenues MAR95 1,500 1,000 Number of observations for the state: 1 ------------------- Sales Region=Northern State=NY ------------------- Month Expenses Revenues FEB95 3,000 4,000 MAR95 6,000 5,000 Number of observations for the state: 2 Sales Figures Grouped by Region and State 2 ------------------- Sales Region=Southern State=FL ------------------- Month Expenses Revenues FEB95 8,500 11,000 MAR95 9,800 13,500 Number of observations for the state: 2 ------------------- Sales Region=Southern State=GA ------------------- Month Expenses Revenues JAN95 2,000 8,000 FEB95 1,200 6,000 Number of observations for the state: 2
options pagesize=60 pageno=1 nodate linesize=70;
Create output for Microsoft Word and specify the file to store the output in. The ODS RTF statement opens the RTF destination and creates output formatted for Microsoft Word. The FILE= option specifies your external file that contains the RTF output. The STARTPAGE =NO option specifies that no new pages be inserted within the PRINT procedure, even if new pages are requested by the procedure code.
ods rtf startpage=no file= ' your_file.rtf '; proc sort data=exprev; by region state month; run; proc print data=exprev n='Number of observations for the state: ' noobs label; var month expenses revenues; by region state; pageby region; label region='Sales Region'; format revenues expenses comma10.; title 'Sales Figures Grouped by Region and State'; run;
Close the RTF destination. The ODS RTF CLOSE statement closes the RTF destination.
ods rtf close;
options pagesize=60 pageno=1 nodate linesize=70; ods rtf file= ' your_file.rtf '; proc sort data=exprev; by region state month; run;
Create a stylized RTF report. The first STYLE option specifies that the background color of the cell containing the number of observations be changed to gray.
The second STYLE option specifies that the background color of the column header for the variable MONTH be changed to white.
The third STYLE option specifies that the background color of the column header for the variable EXPENSES be changed to blue and the font color be changed to white.
The fourth STYLE option specifies that the background color of the column header for the variable REVENUES be changed to gray.
proc print data=exprev n='Number of observations for the state: ' noobs label style(N) = {background=gray}; var month / style(HEADER) = [background = white]; var expenses / style(HEADER) = [background = blue foreground=white]; var revenues / style(HEADER) = [background = gray]; by region state; pageby region; label region='Sales Region'; format revenues expenses comma10.; title 'Sales Figures Grouped by Region and State'; run; ods rtf close;
Procedure features:
PROC PRINT statement options:
N=
BY statement
SUM statement
Other features:
ODS MARKUP statement
SORT procedure
TITLE statement
# BYVAL specification
SAS system options:
BYLINE
NOBYLINE
Data set: EXPREV on page 739
This example
sums expenses and revenues for each region and for all regions
shows the number of observations in each BY group and in the whole report
creates a customized title, containing the name of the region. This title replaces the default BY line for each BY group.
Start each BY group on a new page and suppress the printing of the default BY line. The SAS system option NOBYLINE suppresses the printing of the default BY line. When you use PROC PRINT with NOBYLINE, each BY group starts on a new page.
options nodate pageno=1 linesize=70 pagesize=60 nobyline;
Sort the data set. PROC SORT sorts the observations by Region.
proc sort data=exprev; by region; run;
Print the report, suppress the printing of observation numbers, and print the total number of observations for the selected variables. NOOBS suppresses the printing of observation numbers at the beginning of the rows. N= prints the number of observations in a BY group at the end of that BY group and (because of the SUM statement) prints the number of observations in the data set at the end of the report. The first piece of explanatory text that N= provides precedes the number for each BY group. The second piece of explanatory text that N= provides precedes the number for the entire data set.
proc print data=exprev noobs n='Number of observations for the state: ' 'Number of observations for the data set: ';
Sum the values for the selected variables. The SUM statement alone sums the values of Expenses and Revenues for the entire data set. Because the PROC PRINT step contains a BY statement, the SUM statement also sums the values of Expenses and Revenues for each region that contains more than one observation.
sum expenses revenues; by region;
Format the numeric values for a specified column. The FORMAT statement assigns the COMMA10. format to Expenses and Revenues for this report.
format revenues expenses comma10.;
Specify and format a dynamic (or current) title. The TITLE statement specifies a title. The #BYVAL specification places the current value of the BY variable Region in the title. Because NOBYLINE is in effect, each BY group starts on a new page, and the title serves as a BY line.
title 'Revenue and Expense Totals for the #byval(region) Region'; run;
Generate the default BY line. The SAS system option BYLINE resets the printing of the default BY line.
options byline;
Revenue and Expense Totals for the Northern Region 1 State Month Expenses Revenues NY FEB95 3,000 4,000 NY MAR95 6,000 5,000 MA MAR95 1,500 1,000 ------ ---------- ---------- Region 10,500 10,000 Number of observations for the state: 3
Revenue and Expense Totals for the Southern Region 2 State Month Expenses Revenues GA JAN95 2,000 8,000 GA FEB95 1,200 6,000 FL FEB95 8,500 11,000 FL MAR95 9,800 13,500 ------ ---------- ---------- Region 21,500 38,500 ========== ========== 32,000 48,500 Number of observations for the state: 4 Number of observations for the data set: 7
The following example opens the MARKUP destination. The output file will contain only XML tagging unless you have a browser that reads XML.
options nodate pageno=1 linesize=70 pagesize=60 nobyline;
Produce output that is tagged with Extensible Markup Language (XML) tags and specify the file to store it in. The ODS MARKUP statement opens the MARKUP destination and creates a file containing output that is tagged with XML tags. The FILE= argument specifies your external file that contains the XML output.
ods markup file= ' your_file.xml '; proc sort data=exprev; by region; run; proc print data=exprev noobs n='Number of observations for the state: ' 'Number of observations for the data set: '; sum expenses revenues; by region; format revenues expenses comma10.; title 'Revenue and Expense Totals for the #byval(region) Region'; run; options byline;
Close the MARKUP destination. The ODS RTF CLOSE statement closes the MARKUP destination.
ods markup close;
<?xml version="1.0" encoding="windows-1252"?> <odsxml> <head> <meta operator="user"/> </head> <body> <proc name="Print"> <label name="IDX"/> <title class="SystemTitle" toc-level="1">Revenue and Expense Totals for the Northern Region</title> <branch name="Print" label="The Print Procedure" class="ContentProcName" toc-level="1"> <bygroup> <branch name="ByGroup1" label="ByGroup1" class="ByContentFolder" toc-level="2"> <leaf name="Print" label="Data Set WORK.EXPREV" class="ContentItem" toc-level="3"> <output name="Print" label="Data Set WORK.EXPREV" clabel="Data Set WORK.EXPREV"> <output-object type="table" class="Table"> <style> <border spacing="1" padding="7" rules="groups" frame="box"/> </style> <colspecs columns="4"> <colgroup> <colspec name="1" width="6" type="string"/> <colspec name="2" width="5" type="string"/> <colspec name="3" width="10" type="string"/> <colspec name="4" width="10" type="string"/> </colgroup> ... more lines of XML output ... <row> <data type="string" class="NoteContent" row="8" column="1" column-end="4"> <style> <span columns="4"/> </style> <value>Number of observations for the state: 4<br/>Number of observations for the data set: 7</value> </data> </row> </output-body> </output-object> </output> </leaf> </bygroup> </branch> </branch> </proc> </body> </odsxml>
Procedure features:
BY statement
SUM statement
Other features: SORT procedure
Data set: EXPREV on page 739
This example
sums expenses and revenues for
each region
each state with more than one row in the report
all rows in the report.
shows the number of observations in each BY group and in the whole report.
options nodate pageno=1 linesize=70 pagesize=60;
Sort the data set. PROC SORT sorts the observations by Region and State.
proc sort data=exprev; by region state; run;
Print the report, suppress the printing of observation numbers, and print the total number of observations for the selected variables. The N option prints the number of observations in a BY group at the end of that BY group and prints the total number of observations used in the report at the bottom of the report. NOOBS suppresses the printing of observation numbers at the beginning of the rows.
proc print data=exprev n noobs;
Create a separate section of the report for each BY group, and sum the values for the selected variables. The BY statement produces a separate section of the report for each BY group. The SUM statement alone sums the values of Expenses and Revenues for the entire data set. Because the program contains a BY statement, the SUM statement also sums the values of Expenses and Revenues for each BY group that contains more than one observation.
by region state; sum expenses revenues;
Establish a label for a selected variable, format the values of specified variables, and create a title. The LABEL statement associates a label with the variable Region for the duration of the PROC PRINT step. The BY line at the beginning of each BY group uses the label. The FORMAT statement assigns a format to the variables Expenses and Revenues for this report. The TITLE statement specifies a title.
label region='Sales Region'; format revenues expenses comma10.; title 'Revenue and Expense Totals for Each State and Region'; run;
The report uses default column headers (variable names ) because neither the SPLIT= nor the LABEL option is used. Nevertheless, the BY line at the top of each section of the report shows the BY variables labels and their values. The name of a BY variable identifies the subtotals in the report. PROC PRINT sums Expenses and Revenues for each BY group that contains more than one observation.
However, sums are shown only for the BY variables whose values change from one BY group to the next . For example, in the third BY group, where the sales region is Southern and the state is FL , Expenses and Revenues are summed only for the state because the next BY group is for the same region.
Revenue and Expense Totals for Each State and Region 1 ------------------- Sales Region=Northern State=MA ------------------- Month Expenses Revenues MAR95 1,500 1,000 N = 1 ------------------- Sales Region=Northern State=NY ------------------- Month Expenses Revenues FEB95 3,000 4,000 MAR95 6,000 5,000 ------ ---------- ---------- State 9,000 9,000 Region 10,500 10,000 N = 2 ------------------- Sales Region=Southern State=FL ------------------- Month Expenses Revenues FEB95 8,500 11,000 MAR95 9,800 13,500 ------ ---------- ---------- State 18,300 24,500 N = 2 ------------------- Sales Region=Southern State=GA ------------------- Month Expenses Revenues JAN95 2,000 8,000 FEB95 1,200 6,000 ------ ---------- ---------- State 3,200 14,000 Region 21,500 38,500 ========== ========== 32,000 48,500 N = 2 Total N = 7
options nodate pageno=1 linesize=70 pagesize=60;
Produce HTML output and specify the file to store the output in. The ODS HTML statement opens the HTML destination and creates a file that contains HTML output. The FILE= argument specifies your external file that contains the HTML output.
ods html file= 'your_file.html'; proc sort data=exprev; by region state; run; proc print data=exprev n noobs; by region state; sum expenses revenues; label region='Sales Region'; format revenues expenses comma10.; title 'Revenue and Expense Totals for Each State and Region'; run;
Close the HTML destination. The ODS HTML CLOSE statement closes the HTML destination.
ods html close;
options nodate pageno=1 linesize=70 pagesize=60; ods html file = 'your_file.html' ; proc sort data=exprev; by region state; run; proc print data=exprev n noobs;
Create stylized HTML output. The STYLE option in the first SUM statement specifies that the background color of the cell containing the grand total for the variable EXPENSES be changed to white and the font color be changed to dark gray.
The STYLE option in the second SUM statement specifies that the background color of cells containing totals for the variable REVENUES be changed to blue and the font color be changed to white.
by region state; sum expenses / style(GRANDTOTAL) = [background =white foreground=blue]; sum revenues / style(TOTAL) = [background =dark gray foreground=white]; label region='Sales Region'; format revenues expenses comma10.; title 'Revenue and Expense Totals for Each State and Region'; run; ods html close;
Features:
BY statement
SUM statement
SUMBY statement
Other features:
SORT procedure
LABEL statement
Data set: EXPREV on page 739
This example
creates a separate section of the report for each combination of state and region
sums expenses and revenues only for each region and for all regions, not for individual states.
options nodate pageno=1 linesize=70 pagesize=60;
Sort the data set. PROC SORT sorts the observations by Region and State.
proc sort data=exprev; by region state; run;
Print the report and remove the observation numbers. NOOBS suppresses the printing of observation numbers at the beginning of the rows.
proc print data=exprev noobs;
Sum the values for each region. The SUM and BY statements work together to sum the values of Revenues and Expenses for each BY group as well as for the whole report. The SUMBY statement limits the subtotals to one for each region.
by region state; sum revenues expenses; sumby region;
Assign labels to specific variables. The LABEL statement associates a label with the variable Region for the duration of the PROC PRINT step. This label is used in the BY lines.
label region='Sales Region';
Assign a format to the necessary variables and specify a title. The FORMAT statement assigns the COMMA10. format to Expenses and Revenues for this report.
format revenues expenses comma10.; title 'Revenue and Expense Figures for Each Region'; run;
The report uses default column headers (variable names) because neither the SPLIT= nor the LABEL option is used. Nevertheless, the BY line at the top of each section of the report shows the BY variables labels and their values. The name of a BY variable identifies the subtotals in the report.
Revenue and Expense Figures for Each Region 1 ------------------- Sales Region=Northern State=MA ------------------- Month Expenses Revenues MAR95 1,500 1,000 ------------------- Sales Region=Northern State=NY ------------------- Month Expenses Revenues FEB95 3,000 4,000 MAR95 6,000 5,000 ------ ---------- ---------- Region 10,500 10,000 ------------------- Sales Region=Southern State=FL ------------------- Month Expenses Revenues FEB95 8,500 11,000 MAR95 9,800 13,500 ------------------- Sales Region=Southern State=GA ------------------- Month Expenses Revenues JAN95 2,000 8,000 FEB95 1,200 6,000 ------ ---------- ---------- Region 21,500 38,500 ========== ========== 32,000 48,500
options nodate pageno=1 linesize=70 pagesize=60;
Produce PostScript output and specify the file to store the output in. The ODS PS statement opens the PS destination and creates a file that contains PostScript output. The FILE= argument specifies your external file that contains the PostScript output.
ods ps file= 'your_file.ps' ; proc sort data=exprev; by region state; run; proc print data=exprev noobs; by region state; sum revenues expenses; sumby region; label region='Sales Region'; format revenues expenses comma10.; title 'Revenue and Expense Figures for Each Region'; run;
Close the PS destination. The ODS PS CLOSE statement closes the PS destination.
ods ps close;
options nodate pageno=1 linesize=70 pagesize=60; ods ps file= ' your_file.ps '; proc sort data=exprev; by region state; run; proc print data=exprev noobs; by region state;
Create stylized PostScript output. The STYLE option in the first SUM statement specifies that the background color of cells containing totals for the variable REVENUES be changed to blue and the font color be changed to white.
The STYLE option in the second SUM statement specifies that the background color of the cell containing the grand total for the EXPENSES variable be changed to white and the font color be changed to dark gray.
sum revenues / style(TOTAL) = [background =blue foreground=white]; sum expenses / style(GRANDTOTAL) = [background =white foreground=dark gray]; label region='Sales Region'; format revenues expenses comma10.; title 'Revenue and Expense Figures for Each Region'; run; ods ps close;
Procedure features:
PROC PRINT statement options:
ROWS=
ID statement options:
STYLE
Other features:
ODS RTF statement
SAS data set options:
OBS=
This example shows two ways of printing a data set with a large number of variables: one is the default, and the other uses ROWS=. For detailed explanations of the layouts of these two reports , see the ROWS= option on page 726 and see Page Layout on page 736.
These reports use a pagesize of 24 and a linesize of 64 to help illustrate the different layouts.
Note: When the two reports are written as HTML output, they do not differ .
options nodate pageno=1 linesize=64 pagesize=24 ;
Create the EMPDATA data set. The data set EMPDATA contains personal and job- related information about a company s employees . A DATA step on page 1399 creates this data set.
data empdata; input IdNumber $ 1-4 LastName $ 9-19 FirstName $ 20-29 City $ 30-42 State $ 43-44 / Gender $ 1 JobCode $ 9-11 Salary 20-29 @30 Birth date9. @43 Hired date9. HomePhone $ 54-65; format birth hired date9.; datalines; 1919 Adams Gerald Stamford CT M TA2 34376 15SEP1948 07JUN1975 203/781-1255 1653 Alexander Susan Bridgeport CT F ME2 35108 18OCT1952 12AUG1978 203/675-7715 . . . more lines of data . . . 1407 Grant Daniel Mt. Vernon NY M PT1 68096 26MAR1957 21MAR1978 914/468-1616 1114 Green Janice New York NY F TA2 32928 21SEP1957 30JUN1975 212/588-1092 ;
Print only the first 12 observations in a data set. The OBS= data set option uses only the first 12 observations to create the report. (This is just to conserve space here.) The ID statement identifies observations with the formatted value of IdNumber rather than with the observation number. This report is shown in Example 7 on page 769.
proc print data=empdata(obs=12); id idnumber; title 'Personnel Data'; run;
Print a report that contains only one row of variables on each page. ROWS=PAGE prints only one row of variables for each observation on a page. This report is shown in Example 7 on page 769.
proc print data=empdata(obs=12) rows=page; id idnumber; title 'Personnel Data'; run;
In the traditional procedure output, each page of this report contains values for all variables in each observation. In the HTML output, this report is identical to the report that uses ROWS=PAGE.
Note that PROC PRINT automatically splits the variable names that are used as column headers at a change in capitalization if the entire name does not fit in the column. Compare, for example, the column headers for LastName (which fits in the column) and FirstName (which does not fit in the column).
Personnel Data 1 Id First Number LastName Name City State Gender 1919 Adams Gerald Stamford CT M 1653 Alexander Susan Bridgeport CT F 1400 Apple Troy New York NY M 1350 Arthur Barbara New York NY F 1401 Avery Jerry Paterson NJ M 1499 Barefoot Joseph Princeton NJ M 1101 Baucom Walter New York NY M Id Job Number Code Salary Birth Hired HomePhone 1919 TA2 34376 15SEP48 07JUN75 203/781-1255 1653 ME2 35108 18OCT52 12AUG78 203/675-7715 1400 ME1 29769 08NOV55 19OCT78 212/586-0808 1350 FA3 32886 03SEP53 01AUG78 718/383-1549 1401 TA3 38822 16DEC38 20NOV73 201/732-8787 1499 ME3 43025 29APR42 10JUN68 201/812-5665 1101 SCP 18723 09JUN50 04OCT78 212/586-8060
Personnel Data 2 Id First Number LastName Name City State Gender 1333 Blair Justin Stamford CT M 1402 Blalock Ralph New York NY M 1479 Bostic Marie New York NY F 1403 Bowden Earl Bridgeport CT M 1739 Boyce Jonathan New York NY M Id Job Number Code Salary Birth Hired HomePhone 1333 PT2 88606 02APR49 13FEB69 203/781-1777 1402 TA2 32615 20JAN51 05DEC78 718/384-2849 1479 TA3 38785 25DEC56 08OCT77 718/384-8816 1403 ME1 28072 31JAN57 24DEC79 203/675-3434 1739 PT1 66517 28DEC52 30JAN79 212/587-1247
Each page of this report contains values for only some of the variables in each observation. However, each page contains values for more observations than the default report does.
Personnel Data 1 Id First Number LastName Name City State Gender 1919 Adams Gerald Stamford CT M 1653 Alexander Susan Bridgeport CT F 1400 Apple Troy New York NY M 1350 Arthur Barbara New York NY F 1401 Avery Jerry Paterson NJ M 1499 Barefoot Joseph Princeton NJ M 1101 Baucom Walter New York NY M 1333 Blair Justin Stamford CT M 1402 Blalock Ralph New York NY M 1479 Bostic Marie New York NY F 1403 Bowden Earl Bridgeport CT M 1739 Boyce Jonathan New York NY M
Personnel Data 2 Id Job Number Code Salary Birth Hired HomePhone 1919 TA2 34376 15SEP48 07JUN75 203/781-1255 1653 ME2 35108 18OCT52 12AUG78 203/675-7715 1400 ME1 29769 08NOV55 19OCT78 212/586-0808 1350 FA3 32886 03SEP53 01AUG78 718/383-1549 1401 TA3 38822 16DEC38 20NOV73 201/732-8787 1499 ME3 43025 29APR42 10JUN68 201/812-5665 1101 SCP 18723 09JUN50 04OCT78 212/586-8060 1333 PT2 88606 02APR49 13FEB69 203/781-1777 1402 TA2 32615 20JAN51 05DEC78 718/384-2849 1479 TA3 38785 25DEC56 08OCT77 718/384-8816 1403 ME1 28072 31JAN57 24DEC79 203/675-3434 1739 PT1 66517 28DEC52 30JAN79 212/587-1247
options nodate pageno=1 linesize=64 pagesize=24; data empdata; input IdNumber $ 1-4 LastName $ 9-19 FirstName $ 20-29 City $ 30-42 State $ 43-44 / Gender $ 1 JobCode $ 9-11 Salary 20-29 @30 Birth date9. @43 Hired date9. HomePhone $ 54-65; format birth hired date9.; datalines; 1919 Adams Gerald Stamford CT M TA2 34376 15SEP1948 07JUN1975 203/781-1255 1653 Alexander Susan Bridgeport CT F ME2 35108 18OCT1952 12AUG1978 203/675-7715 . . . more lines of data . . . 1407 Grant Daniel Mt. Vernon NY M PT1 68096 26MAR1957 21MAR1978 914/468-1616 1114 Green Janice New York NY F TA2 32928 21SEP1957 30JUN1975 212/588-1092 ;
Create output for Microsoft Word and specify the file to store the output in. The ODS RTF statement opens the RTF destination and creates output formatted for Microsoft Word. The FILE= argument specifies your external file that contains the RTF output.
ods rtf file= ' your_file.rtf '; proc print data=empdata(obs=12); id idnumber; title 'Personnel Data'; run;
Close the RTF destination. The ODS RTF CLOSE statement closes the RTF destination.
ods rtf close;
options nodate pageno=1 linesize=64 pagesize=24; data empdata; input IdNumber $ 1-4 LastName $ 9-19 FirstName $ 20-29 City $ 30-42 State $ 43-44 / Gender $ 1 JobCode $ 9-11 Salary 20-29 @30 Birth date9. @43 Hired date9. HomePhone $ 54-65; format birth hired date9.; datalines; 1919 Adams Gerald Stamford CT M TA2 34376 15SEP1948 07JUN1975 203/781-1255 1653 Alexander Susan Bridgeport CT F ME2 35108 18OCT1952 12AUG1978 203/675-7715 ... more lines of data ... 1407 Grant Daniel Mt. Vernon NY M PT1 68096 26MAR1957 21MAR1978 914/468-1616 1114 Green Janice New York NY F TA2 32928 21SEP1957 30JUN1975 212/588-1092 ; ods rtf file= ' your_file.rtf '; proc print data=empdata(obs=12);
Create stylized output for Microsoft Word.
id idnumber / style(DATA) = {background = red foreground = white} style(HEADER) = {background = blue foreground = white}; title 'Personnel Data'; run; ods rtf close;
Procedure features:
BY statement
ID statement
SUM statement
VAR statement
Other features:
SORT procedure
Data set: EMPDATA on page 770
This customized report
selects variables to include in the report and controls their order
selects observations to include in the report
groups the selected observations by JobCode
sums the salaries for each job code and for all job codes
displays numeric data with commas and dollar signs.
Create and sort a temporary data set. PROC SORT creates a temporary data set in which the observations are sorted by JobCode and Gender.
options nodate pageno=1 linesize=64 pagesize=60; proc sort data=empdata out=tempemp; by jobcode gender; run;
Identify the character that starts a new line in column headers. SPLIT= identifies the asterisk as the character that starts a new line in column headers.
proc print data=tempemp split='*';
Specify the variables to include in the report. The VAR statement and the ID statement together select the variables to include in the report. The ID statement and the BY statement produce the special format.
id jobcode; by jobcode; var gender salary;
Calculate the total value for each BY group. The SUM statement totals the values of Salary for each BY group and for the whole report.
sum salary;
Assign labels to the appropriate variables. The LABEL statement associates a label with each variable for the duration of the PROC PRINT step. When you use SPLIT= in the PROC PRINT statement, the procedure uses labels for column headings.
label jobcode='Job Code*========' gender='Gender*======' salary='Annual Salary*=============';
Create formatted columns. The FORMAT statement assigns a format to Salary for this report. The WHERE statement selects for the report only the observations for job codes that contain the letters FA or ME . The TITLE statements specify two titles.
format salary dollar11.2; where jobcode contains 'FA' or jobcode contains 'ME'; title 'Expenses Incurred for'; title2 'Salaries for Flight Attendants and Mechanics'; run;
The ID and BY statements work together to produce this layout. The ID variable is listed only once for each BY group. The BY lines are suppressed. Instead, the value of the ID variable, JobCode, identifies each BY group.
Expenses Incurred for 1 Salaries for Flight Attendants and Mechanics Job Code Gender Annual Salary ======== ====== ============= FA1 F ,177.00 F ,454.00 M ,268.00 -------- ------------- FA1 ,899.00 FA2 F ,888.00 F ,787.00 M ,572.00 -------- ------------- FA2 ,247.00 FA3 F ,886.00 F ,419.00 M ,217.00 -------- ------------- FA3 ,522.00 ME1 M ,769.00 M ,072.00 M ,619.00 -------- ------------- ME1 ,460.00 ME2 F ,108.00 F ,929.00 M ,345.00 M ,925.00 M ,090.00 M ,185.00 -------- ------------- ME2 2,582.00 ME3 M ,025.00 ============= 3,735.00
options nodate pageno=1 linesize=64 pagesize=60 obs=15; proc sort data=empdata out=tempemp; by jobcode gender; run;
Produce HTML output and specify the file to store the output in. The ODS HTML statement opens the HTML destination and creates a file that contains HTML output. The FILE= argument specifies your external file that contains the HTML output.
ods html file='your_file.html'; proc print data=tempemp (obs=10) split='*'; id jobcode; by jobcode; var gender salary; sum salary; label jobcode='Job Code*========' gender='Gender*======' salary='Annual Salary*============='; format salary dollar11.2; where jobcode contains 'FA' or jobcode contains 'ME'; title 'Expenses Incurred for'; title2 'Salaries for Flight Attendants and Mechanics'; run;
Close the HTML destination. The ODS HTML CLOSE statement closes the HTML destination.
ods html close;
options nodate pageno=1 linesize=64 pagesize=60 obs=15; proc sort data=empdata out=tempemp; by jobcode gender; run; ods html file='your_file.html';
Create stylized HTML output. The first STYLE option specifies that the font of the headers be changed to italic. The second STYLE option specifies that the background of cells that contain input data be changed to blue and the foreground of these cells be changed to white.
proc print data=tempemp (obs=10) split='*' style(HEADER) = {font_style=italic} style(DATA) = {background=blue foreground = white}; id jobcode; by jobcode; var gender salary;
Create total values that are written in red. The STYLE option specifies that the color of the foreground of the cell that contain the totals be changed to red.
sum salary / style(total)= [foreground=red]; label jobcode='Job Code*========' gender='Gender*======' salary='Annual Salary*============='; format salary dollar11.2; where jobcode contains 'FA' or jobcode contains 'ME'; title 'Expenses Incurred for'; title2 'Salaries for Flight Attendants and Mechanics'; run; ods html close;
Features:
Macro facility
DATASETS procedure
PRINT procedure
Data set: EXPREV on page 739 and LIST
This example prints all the data sets in a SAS library. You can use the same programming logic with any procedure. Just replace the PROC PRINT step near the end of the example with whatever procedure step you want to execute. The example uses the macro language. For details about the macro language, see SAS Guide to Macro Processing, Version 6, Second Edition .
libname printlib ' SAS-data-library ' options nodate pageno=1 linesize=80 pagesize=60;
Copy the desired data sets from the WORK library to a permanent library. PROC DATASETS copies two data sets from the WORK library to the PRINTLIB library in order to limit the number of data sets available to the example.
proc datasets library=work memtype=data nolist; copy out=printlib; select list exprev; run;
Create a macro and specify the parameters. The %MACRO statement creates the macro PRINTALL. When you call the macro, you can pass one or two parameters to it. The first parameter is the name of the library whose data set you want to print. The second parameter is a library used by the macro. If you do not specify this parameter, the WORK library is the default.
%macro printall(libname,worklib=work);
Create the local macro variables. The %LOCAL statement creates two local macro variables, NUM and I, to use in a loop.
%local num i;
Produce an output data set. This PROC DATASETS step reads the library that you specify as a parameter when you invoke the macro. The CONTENTS statement produces an output data set called TEMP1 in WORKLIB. This data set contains an observation for each variable in each data set in the library LIBNAME. By default, each observation includes the name of the data set that the variable is included in as well as other information about the variable. However, the KEEP= data set option writes only the name of the data set to TEMP1.
proc datasets library=&libname memtype=data nodetails; contents out=&worklib..temp1(keep=memname) data=_all_ noprint; run;
Specify the unique values in the data set, assign a macro variable to each one, and assign DATA step information to a macro variable. This DATA step increments the value of N each time it reads the last occurrence of a data set name (when IF LAST.MEMNAME is true). The CALL SYMPUT statement uses the current value of N to create a macro variable for each unique value of MEMNAME in the data set TEMP1. The TRIM function removes extra blanks in the TITLE statement in the PROC PRINT step that follows .
data _null_; set &worklib..temp1 end=final; by memname notsorted; if last.memname; n+1; call symput('ds'left(put(n,8.)),trim(memname));
When it reads the last observation in the data set (when FINAL is true), the DATA step assigns the value of N to the macro variable NUM. At this point in the program, the value of N is the number of observations in the data set.
if final then call symput('num',put(n,8.));
Run the DATA step. The RUN statement is crucial. It forces the DATA step to run, thus creating the macro variables that are used in the CALL SYMPUT statements before the %DO loop, which uses them, executes.
run;
Print the data sets and end the macro. The %DO loop issues a PROC PRINT step for each data set. The %MEND statement ends the macro.
%do i=1 %to # proc print data=&libname..&&ds&i noobs; title "Data Set &libname..&&ds&i"; run; %end; %mend printall;
Print all the data sets in the PRINTLIB library. This invocation of the PRINTALL macro prints all the data sets in the library PRINTLIB.
options nodate pageno=1 linesize=70 pagesize=60; %printall(printlib)
Data Set printlib.EXPREV 1 Region State Month Expenses Revenues Northern MA MAR95 1500 1000 Northern NY FEB95 3000 4000 Northern NY MAR95 6000 5000 Southern FL FEB95 8500 11000 Southern FL MAR95 9800 13500 Southern GA JAN95 2000 8000 Southern GA FEB95 1200 6000
Data Set printlib.LIST 2 Name Street City State Zip Gabrielli, Theresa 24 Ridgetop Rd. Westboro MA 01581 Clayton, Aria 314 Bridge St. Hanover NH 03755 Dix, Martin L. 4 Shepherd St. Norwich VT 05055 Slater, Emily C. 2009 Cherry St. York PA 17407 Ericson, Jane 211 Clancey Court Chapel Hill NC 27514 An, Ing 95 Willow Dr. Charlotte NC 28211 Jacobson, Becky 7 Lincoln St. Tallahassee FL 32312 Misiewicz, Jeremy 43-C Lakeview Apts. Madison WI 53704 Ahmadi, Hafez 5203 Marston Way Boulder CO 80302 Archuleta, Ruby Box 108 Milagro NM 87429