KEMBAR78
SAS PROC PRINT Guide | PDF | Comma Separated Values | Microsoft Excel
0% found this document useful (0 votes)
75 views8 pages

SAS PROC PRINT Guide

The PROC PRINT procedure prints out variables from a SAS dataset. It can optionally print subtotals and totals for numeric variables. Variables, ID variables, BY groups, and options like page breaks, subtotals, and totals can be specified. The output can be customized with titles, footnotes, headers, and styles. It can also convert the output to various formats like HTML, PDF, Excel, and CSV.

Uploaded by

james
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views8 pages

SAS PROC PRINT Guide

The PROC PRINT procedure prints out variables from a SAS dataset. It can optionally print subtotals and totals for numeric variables. Variables, ID variables, BY groups, and options like page breaks, subtotals, and totals can be specified. The output can be customized with titles, footnotes, headers, and styles. It can also convert the output to various formats like HTML, PDF, Excel, and CSV.

Uploaded by

james
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

PROC PRINT

This procedure prints out all or some of the variables in SAS dataset
And optionally prints out total and sub totals for numeric variables.

Syntax:-
PROC PRINT < OPTIONS>;
VAR VARIABLE-LIST;
ID VARIABLE- LIST;
BY VARIABLE-LIST;
PAGE BY BY-VARIABLE;
SUM BY BY-VARIABLE;
SUM VARIABLE –LIST;
RUN;

Data is available in below CSV file.

Examples:-

PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA;


RUN;

Options:-
Noobs – Suppresses printing observations
PROC PRINT DATA= My_SAS.DEMOGRAPHIC_DATA NOOBS;
RUN;
Obs = Name – Assigns a name for Obs column
PROC PRINT DATA= My_SAS.DEMOGRAPHIC_DATA OBS=‘ROW ’;
RUN;
HEADING= VERTICAL – Prints Column names vertically in output.
PROC PRINT DATA= My_SAS.DEMOGRAPHIC_DATA OBS=‘ROW ’ HEADING=VERTICAL;
RUN;
Double - Double spaces the printed output
PROC PRINT DATA= My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE;
RUN;
N - Prints no of observations.
PROC PRINT DATA= My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N;
RUN;
Label - Variable labels as column headings.
PROC PRINT DATA= My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N LABEL;
LABEL SEX=GENDER INCOME=SALARY;
RUN;
Spilt - The label for variables is split across multiple lines
PROC PRINT DATA= My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*';
LABEL SEX=GENDER
INCOME=SALARY
EMP_ID=EMPLOYEE*ID
EMP_NAME=EMPLOYEE*NAME;
RUN;

Uniform - Formats all pages uniformly.


PROC PRINT DATA= My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM;
LABEL SEX=GENDER
INCOME=SALARY
EMP_ID=EMPLOYEE*ID
EMP_NAME=EMPLOYEE*NAME;
RUN;
Round - Round values to number of decimal places.
PROC PRINT DATA= My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM ROUND;
LABEL SEX=GENDER
INCOME=SALARY
EMP_ID=EMPLOYEE*ID
EMP_NAME=EMPLOYEE*NAME;
RUN;

Statements with Options


Var Statement: - To select the variables which we required into output
PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME SEX INCOME;
RUN;

Where Statement: - Select data into output based on condition


PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME SEX INCOME;
WHERE SEX='M';
/*WHERE SEX='F';*/
RUN;
ID Statement: - ID variable comes the position of OBS place.
PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME SEX INCOME;
ID ZONE;
RUN;

After remove ZONE from VAR statement.

PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N


LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME SEX INCOME;
ID ZONE;
RUN;

BY Statement: - Prints data separately on each group of BY variable.


Where ever we are using by statement, it should be in sorting order
PROC SORT DATA=My_SAS.DEMOGRAPHIC_DATA;
BY ZONE;
RUN;

PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N


LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME SEX INCOME;
BY ZONE;
RUN;

PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N


LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME SEX INCOME;
ID ZONE;
BY ZONE;
RUN;

PAGEBY Statement: - Prints data separately on each group of BY variable in


Separate page.
PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME SEX INCOME;
BY ZONE;
PAGEBY ZONE;
RUN;
SUMBY Statement: - Prints subtotals and totals for all the numeric variables,
Prints subtotals based on each group of BY variable
PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME SEX
AGE INCOME;
BY ZONE;
PAGEBY ZONE;
SUMBY ZONE;
RUN;
SUM Statement: - Prints subtotals and totals for specific numeric variables
PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME SEX
AGE INCOME;
BY ZONE;
PAGEBY ZONE;
SUMBY ZONE;
SUM INCOME;
RUN;
TITLE: - Assigns title for the report, generally it should be in top of the report
The default title is SAS SYSTEM
It is a global option, u can write anywhere in the program
Maximum we can write 10 titles.

FOOTNOTE: - Assigns footnote for the report, generally it should be bottom of


the report
It is a global option, u can write anywhere in the program
Maximum we can write 10 footnotes.

PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N


LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME SEX
AGE INCOME;
BY ZONE;
PAGEBY ZONE;
SUMBY ZONE;
SUM INCOME;
Title1 ' Employee Demographic Data';
Title2 'ROW Technologies ';
Footnote 'Generated By Mr. Raj ';
RUN;
PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME SEX
AGE INCOME;
BY ZONE;
PAGEBY ZONE;
SUMBY ZONE;
SUM INCOME;
Title j=l c=red f=Arial h=7 ' Employee Demographic Data';
Title2 j=r c=blue f=Arial h=6 'ROW Software Solutions ';
Footnote j=l c=green f='comic sans ms' h=7 'Generated by Mr. Raj ';
RUN;

Likewise we can give a maximum of 10 headers and footers.

Applying styles in proc print

PROC FORMAT;
VALUE $val 'F'='RED'
'M'='GREEN';
RUN;

PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N


LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME INCOME
SEX/style=[foreground=$val.] ;
BY ZONE;
PAGEBY ZONE;
SUMBY ZONE;
SUM INCOME;
Title j=l c=red f=Arial h=7 ' Employee Demographic Data';
Title2 j=r c=blue f=Arial h=6 'ROW Software Solutions ';
Footnote j=l c=green f='comic sans ms' h=7 'Generated by Mr. Raj ';
RUN;

Converting Report into user format (HTML)

ODS HTML
FILE="C:\Documents and Settings\Neeru\Desktop\Reports\Demographic.html";
PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME INCOME
SEX/style=[background=$val.] ;
BY ZONE;
PAGEBY ZONE;
SUMBY ZONE;
SUM INCOME;
Title c=red f=Arial h=7 ' Employee Demographic Data';
Title2 c=red f=Arial h=7 'Neeru Technologies ';
Footnote j=l c=green f='comic sans ms' h=7 'Generated by Mr. Raj ';
RUN;
ODS HTML CLOSE;
Output

Converting Report into user format (Pdf)


ODS PDF
FILE="C:\Documents and Settings\Neeru\Desktop\Reports\Demographic.PDF" NOTOC;
PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME INCOME
SEX/style=[foreground=$val.] ;
BY ZONE;
PAGEBY ZONE;
SUMBY ZONE;
SUM INCOME;
Title c=red f=Arial h=7 ' Employee Demographic Data';
Title2 c=red f=Arial h=7 'Neeru Technologies ';
Footnote j=l c=green f='comic sans ms' h=7 'Generated by Mr. Raj ';
RUN;
ODS PDF CLOSE;
Output
Converting Report into user format (Excel)
ODS tagsets.excelxp
FILE="C:\Documents and Settings\Neeru\Desktop\Reports\Demographic.xls" ;
PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME INCOME
SEX/style=[foreground=$val.] ;
BY ZONE;
PAGEBY ZONE;
SUMBY ZONE;
SUM INCOME;
Title c=red f=Arial h=7 ' Employee Demographic Data';
Title2 c=red f=Arial h=7 'Neeru Technologies ';
Footnote j=l c=green f='comic sans ms' h=7 'Generated by Mr. Raj ';
RUN;
ODS tagsets.excelxp CLOSE;
Output

Converting Report into user format (CSV)


PROC FORMAT;
VALUE $val 'F'='RED'
'M'='GREEN';
RUN;
ods csv file = 'd:\samp_output.csv';
PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME INCOME
SEX/style=[foreground=$val.] ;
BY ZONE;
PAGEBY ZONE;
SUMBY ZONE;
SUM INCOME;
Title j=l c=red f=Arial h=7 ' Employee Demographic Data';
Title2 j=r c=blue f=Arial h=6 'ROW Software Solutions ';
Footnote j=c c=green f='comic sans ms' h=7 'Generated by Mr. Raj ';
RUN;
ods csv close;
Converting Report into user format (rtf)
PROC FORMAT;
VALUE $val 'F'='RED'
'M'='GREEN';
RUN;
ods rtf file = 'd:\samp_output.rtf’;
PROC PRINT DATA=My_SAS.DEMOGRAPHIC_DATA NOOBS DOUBLE N
LABEL SPLIT='*' UNIFORM ROUND;
LABEL ZONAL_HEAD=ZONAL*MANAGER
REGIONAL_MANAGER = REGIONAL*MANAGER
EMP_NAME=EMPLOYEE*NAME;
VAR ZONE ZONAL_HEAD REGION REGIONAL_MANAGER EMP_NAME INCOME
SEX/style=[foreground=$val.] ;
BY ZONE;
PAGEBY ZONE;
SUMBY ZONE;
SUM INCOME;
Title j=l c=red f=Arial h=7 ' Employee Demographic Data';
Title2 j=r c=blue f=Arial h=6 'ROW Software Solutions ';
Footnote j=c c=green f='comic sans ms' h=7 'Generated by Mr. Raj ';
RUN;
ods rtf close;

You might also like