• Home
  • /
  • BASE SAS
  • /
  • 3 Little Tricks To Achieve The Best Results In PROC PRINT SAS.

0 Comments

June 22, 2020

PROC PRINT is a type of procedures that are used by every SAS programmer frequently. Most of you must be using it to just to display your data but you can also use it to generate pretty formatted outputs.

Below are some of the things that you can do with PRINT that may make even this standard procedure extra helpful.

Using the ID and BY Statements in PROC PRINT

You can use the ID and BY statements together Although the PROC PRINT procedure doesn’t have a CLASS statement you possibly can offset groups with a combination of the BY and ID statements.

Variables that are common to these two statements will group the other variables and insert a blank line after each group.

proc sort data=sashelp.class out=class2;
by sex;
run;
proc print data=class2;
by sex;
id sex;
var name age weight;
run;

Proc Print SAS

    • In the PRINT step, both the BY and ID statements use the variable SEX. When used together in this manner, the value for SEX is written only once for each SEX. This is also the default behaviour for PROC REPORT for GROUP and ORDER variables.
    • A blank line has been inserted after each SEX.

Note: It is important that the variables used in the BY statements are sorted.

Using the STYLE= Option with PROC PRINT

The STYLE= option is used to alter the attributes generated by the selected ODS style.

Below is the general syntax and the attributes are surrounded by curly brackets.

style<(location)>={attribute=attribute_value}

In the current releases of SAS, you’ll be able to use the square bracket as an alternative of the curly braces. Specification of the location is non-obligatory since there’s a default assignment when it’s left off.

However, you usually will want to specify the location as it is used to manage the place the
attribute assignment is to be applied. The supported locations that you can include are:

  • DATA cells (also COLUMNS or COL)
  • TOTAL sub-total (used on the SUM statement)
  • GRANDTOTAL overall total (used on the SUM statement)
  • HEADER column header (also HEAD and HDR)
  • N used when the N option is specified
  • OBS cells in the OBS column
  • OBSHEADER header for the OBS column
  • TABLE controls table structure resembling cell width

You can apply the STYLE= option to the PROC PRINT statement as well as on other proc step statements. A combination of the desired location and the statement containing the option will decide what portion of the table is modified by the option.

Not all style option locations are applicable for all PRINT statements. The following table reveals the available locations and the statements to which they are often applied.

PROC STATEMENTSSupported Style Locations
PROC PRINTdata header, n, obs, obsheader, table
BYnone
IDheader, data
VARheader, data
SUMheader, data, total, grandtotal

You can modify some of the style attributes like-

  • BACKGROUND
  • BORDERCOLOR
  • BORDERCOLORDARK
  • BORDERCOLORLIGHT
  • FONT_FACE
  • FONT_WEIGHT
  • FOREGROUND

Other Options

Although style attributes used with the PROC statement usually apply to the table as a whole, STYLE= options that are applied to supporting statements can provide you with extra control in the styling.

For example, you may want the first column to be of different background colour.

Additionally, these attributes are likely to override these settings on the PROC statement.
Like the CLASS statement which can be split into a number of statements, several of the PRINT statements that allow lists of variables can be split into a number of statements.

This lets you specify completely different options for different variables.

proc print data=sashelp.cars (obs=10) noobs label 
style(col)=[backgroundcolor=lightcyan]
style(header)= [background=yellow font_weight=bold]
style(obs)= [background=lightred]
n='Count of Model = '
;
var origin/style(header)=[backgroundcolor=lightcoral] 
           style(column)=[backgroundcolor=lightpink foreground=blue];
var origin Make Model MSRP;
sum MSRP/style(grandtotal)=[backgroundcolor=darkgreen foreground=white];
title1 "Sum of MSRP";
footnote1 "Note: Number of Records are limited to 10";
footnote2 "DATASET: SASHELP.CARS"; 
run;

Proc Print SAS

Note the NOBS option is used to eliminate the OBS column. The LABEL allows column labels that are not just variable names.

The SUM statement allows for a summary of numbers to be produced in the listing and it is useful when subgroup and total summaries need to be generated, while the N option prints the number of observations.

Two locations(header, column) are specified for the ORIGIN variable.

The grand total receives two attribute overrides- backgroundcolor and foreground.

Using PROC PRINT to Generate a Table of Contents

The PRINT procedure is designed to work with lists of data. When the list of values
contains hyperlinks to different files, PRINT can create a table of contents to a report.

In this instance, HTML anchor tags are formed as data values. When they are displayed by ODS in the HTML destination these values change into hyperlinks to different files.

The character variable CLINIC is used to hold the HTML anchor tag. The CATT function n is used as an anchor tag statement.

The clinic number o is used in the name of the clinic p will be  step q all that’s required is to destination doesn’t know what to do with an HTML anchor tag and can subsequently show the data as it’s stored

When the table is displayed using the HTML destination, the value is interpreted as an anchor tag and is displayed as a linkable item. Here the first 4 items in the PROC PRINT are shown.

data Links; 
length websites $70;
input websites;
datalines;
Google
Facebook
Apple
Microsoft
; 
run;
data toc;
set links;
weblinks=catt("<a href='https://www.",lowcase(websites),".com'>",websites,"</a>");
run; 
ods html body=toc.html;
proc print data=toc;
run;
ods html close;

Proc print SAS

related posts:


Column Input in SAS to Read Raw Data Arranged in Columns


Date Interval Functions – INTNX and INTCK in SAS


SAS Generation Datasets

Subhro Kar

About the author

Been in the realm with the professionals of the IT industry. I am passionate about Coding, Blogging, Web Designing and deliver creative and useful content for a wide array of audience.

Subhro

Leave a Reply

Your email address will not be published. Required fields are marked

This site uses Akismet to reduce spam. Learn how your comment data is processed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}