You are on page 1of 33

SASTechies

info@sastechies.com
http://www.sastechies.com
 Creating

◦ SAS Tables,
◦ Listings,
◦ Basic Statistics Procedures with
SAS TLG’s
◦ Graphs
◦ ODS HTML
◦ Proc Report and Other Utility
Procedures

SAS Techies 2009 11/02/21 2


append printto
catalog rank
cimport report
compare sql
contents sort
cport summary
datasets tabulate
export template
format transpose
import
options
print

SAS Techies 2009 11/02/21 3


 The REPORT procedure
combines features of the
PRINT, MEANS, and TABULATE
procedures with features of the
DATA step in a single report-
writing tool that can produce a
variety of reports.

 A detail report contains one


row for every observation
selected for the report. Each of
these rows is a detail row. A
summary report consolidates
data so that each row
represents multiple
observations

SAS Techies 2009 11/02/21 4


SAS Techies 2009 11/02/21 5
PROC REPORT Statement
BREAK Statement
BY Statement - By Group processing
CALL DEFINE Statement
COLUMN Statement - Specify the columns in the report
COMPUTE Statement
DEFINE Statement
ENDCOMP Statement
FREQ Statement - Freq statistics
LINE Statement
RBREAK Statement
WEIGHT Statement - calculating weighted statistics

SAS Techies 2009 11/02/21 6


options nodate pageno=1 linesize=64
pagesize=60
Sales Figures for Northern Sectors fmtsearch=(proclib);

proc report data=grocery nowd headline


Sector Manager Sales headskip;
column sector manager sales;
Northeast Alomar 786.00 define sector / group 'Sector';
define manager / group 'Manager';
  Andrews 1,045.00
define sales / analysis sum format=comma10.2
    $1,831.00 'Sales';
break after sector / ol summarize suppress skip;
Northwest Brown 598.00 compute after;
  Pelfrey 746.00 line 'Combined sales for the northern sectors
were '
  Reveiz 1,110.00 sales.sum dollar9.2 '.';
endcomp;
    $2,454.00
Combined sales for the northern sectors were $4,285.00 compute sales;
. if _break_ ne ' ' then
call define(_col_,"format","dollar11.2");
endcomp;
where sector contains 'n';
title 'Sales Figures for Northern Sectors';
run;

SAS Techies 2009 11/02/21 7


break after sector / ol  Break: Produces a default
summarize suppress summary at a break (a
change in the value of a
skip; group or order variable). The
information in a summary
Double overline each value DOL *
applies to a set of
Double underline each value DUL *
observations.
Overline each value OL *

Start a new page after the last break line PAGE  Rbreak: Produces a default
Write a blank line for the last break line SKIP summary at the beginning or
Specify a style element for default summary STYLE= end of a report or at the
lines, customized summary lines or both beginning or end of each BY
Write a summary line in each group of break SUMMARIZE group.
lines
Suppress the printing of the value of the break SUPPRESS
variable in the summary line and of any
underlining or overlining in the break lines in
the column containing the break variable

SAS Techies 2009 11/02/21 8


 CALL DEFINE (column-id | _ROW_ , ◦ Sets the value of an attribute for a
particular column in the current row.
'attribute-name', value); ◦ Used heavily for Traffic lighting and many
formatting purposes

Attribute Description Values


BLINK Controls blinking of current value 1 turns blinking on; 0 turns it off
COLOR Controls the color of the current 'blue', 'red', 'pink', 'green', 'cyan',
value in the REPORT window 'orange', 'black',
COMMAND Specifies that a series of commands a quoted string of SAS
follows commands to submit to the
command line
FORMAT Specifies a format for the column a SAS format or a user-defined
format
HIGHLIGHT Controls highlighting of the current 1 turns highlighting on; 0 turns it
value off
RVSVIDEO Controls display of the current value 1 turns reverse video on; 0 turns
it off
STYLE= Specifies the style element for the See Using the STYLE= Attribute
Output Delivery System

SAS Techies 2009 11/02/21 9


 COMPUTE location <target>
</ STYLE=<style-element-name>
 A compute block can be
<[style-attribute-specification(s) ]>>; LINE associated with a report item
specification(s); . . . or with a location (at the top or
select SAS language elements . . .
bottom of a report; at the top
ENDCOMP;
or bottom of a page; before or
after a set of observations).

SAS Techies 2009 11/02/21 10


Define the item, which must be a data set variable, as an across variable ACROSS

Define the item, which must be a data set variable, as an analysis variable ANALYSIS

Define the item as a computed variable COMPUTED

Define the item, which must be a data set variable, as a display variable DISPLAY

Define the item, which must be a data set variable, as a group variable GROUP

Define the item, which must be a data set variable, as an order variable ORDER

Assign a SAS or user-defined format to the item FORMAT=

Associate a statistic with an analysis variable statistic

Specify a style element (for the Output Delivery System) for the report item STYLE=

Specify a numeric variable whose values weight the value of the analysis WEIGHT=
variable

Define the width of the column in which PROC REPORT displays the report item WIDTH=

SAS Techies 2009 11/02/21 11


options nodate pageno=1 linesize=64
pagesize=60
Sales Figures for Northern Sectors fmtsearch=(proclib);

proc report data=grocery nowd headline


Sector Manager Sales headskip;
column sector manager sales;
Northeast Alomar 786.00 define sector / group 'Sector';
define manager / group 'Manager';
  Andrews 1,045.00
define sales / analysis sum format=comma10.2
    $1,831.00 'Sales';
break after sector / ol summarize suppress skip;
Northwest Brown 598.00 compute after;
  Pelfrey 746.00 line 'Combined sales for the northern sectors
were '
  Reveiz 1,110.00 sales.sum dollar9.2 '.';
endcomp;
    $2,454.00
Combined sales for the northern sectors were $4,285.00 compute sales;
. if _break_ ne ' ' then
call define(_col_,"format","dollar11.2");
endcomp;
where sector contains 'n';
title 'Sales Figures for Northern Sectors';
run;

SAS Techies 2009 11/02/21 12


proc report data=grocery nowd
colwidth=10
spacing=5
headline headskip;
Sales for the Southeast Sector column manager department sales;
Manager Department Sales define manager / order order=formatted ;
Jones Paper $40.00
define department / order order=internal;
define sales / analysis sum
  Canned $220.00 format=dollar7.2;
break after manager / ol
  Meat/Dairy $300.00 summarize
skip;
  Produce $70.00
Jones   $630.00 compute after;
line 'Total sales for these stores were: '
Smith Paper $50.00 sales.sum dollar9.2;
endcomp;
  Canned $120.00
  Meat/Dairy $100.00 where sector='se';
  Produce $80.00 title 'Sales for the Southeast Sector';
run;
Smith   $350.00
Total sales for these stores were:   $980.00

SAS Techies 2009 11/02/21 13


 PROC APPEND BASE=<libref.>SAS-data-set
<DATA=<libref.>SAS-data-set> <FORCE>
 The APPEND procedure
<APPENDVER=V6>; adds the observations from
one SAS data set to the end
 proc append base=exp.results
data=exp.sur force; run;
of another SAS data set.
Data new; FORCE Option -
Set a b; a=20 b=20 new=40  forces the APPEND
Run;
statement to concatenate
proc append base=a data=b force; run; data sets when the DATA=
data set contains variables
Initially a=20 b=20 after append a=40 that either
Data a;
◦ are not in the BASE= data set
Set a b; initially a=20 b=20 after append ◦ do not have the same type
Run; a=40 as the variables in the BASE=
data set
Advantage Proc Append – Does not read ◦ are longer than the variables
contents of dsn a to PDV…performance
increases..mostly used for monthly updates in the BASE= data set.
and reporting in the industry.

SAS Techies 2009 11/02/21 14


PROC CATALOG  The CATALOG procedure
CATALOG=<libref.>catalog manages entries in SAS
<ENTRYTYPE=etype> <FORCE>
<KILL>; catalogs. PROC CATALOG is
CONTENTS <OUT=SAS-data-set> an interactive, statement-
<FILE=fileref>; driven procedure that
COPY OUT=<libref.>catalog <options>; enables you to
SELECT entry(s) </ ENTRYTYPE=etype>; ◦ create a listing of the contents
EXCLUDE entry(s) </ ENTRYTYPE=etype>; of a catalog
CHANGE old-name-1=new-name-1 ◦ copy a catalog or selected
<...old-name-n=new-name-n> entries within a catalog
</ ENTRYTYPE=etype>; ◦ rename, exchange, or delete
EXCHANGE name-1=other-name-1 entries within a catalog
<...name-n=other-name-n> ◦ change the name of a catalog
</ ENTRYTYPE=etype>;
entry
DELETE entry(s) </ ENTRYTYPE=etype>;
◦ modify, by changing or
MODIFY entry (DESCRIPTION=<<'>entry- deleting, the description of a
description<'>>)</
ENTRYTYPE=etype>; catalog entry.
SAVE entry(s) </ ENTRYTYPE=etype>;

SAS Techies 2009 11/02/21 15


options nodate pageno=1 linesize=80 pagesize=60 source;
libname perm 'SAS-data-library';
proc catalog cat=perm.sample;
delete credit.program credit.log;
copy out=tcatall;
copy out=testcat;
exclude test1 test2 test3 passist (et=slist) / et=log;
run; * RUN GROUP PROCESSING
copy in=perm.formats out=perm.finance;
select revenue.format dept.formatc;
quit;

SAS Techies 2009 11/02/21 16


 Transport files are created to migrate SAS datasets between
platforms (Unix, MVS, Windows) and continue using the same SAS
Data Sets as simple transfer of true SAS Data Sets between operating
systems will corrupt them.

 To accomplish the transfer of SAS Data Sets from one operating


system to another it is necessary to
◦ convert the data set into "transport" format (Proc CPort)
◦ move, send or carry the data in "binary" (i.e., non-translated)
format to the operating system running the other Version
◦ convert the transport data set back into a SAS Data Set (Proc
Cimport)

 Transport files are sequential files that each contain a SAS data
library, a SAS catalog, or a SAS data set in transport format.
 The transport format that PROC CPORT writes is the same for all
environments and for many releases of SAS.

SAS Techies 2009 11/02/21 17


PROC CPORT source-type=libref |
<libref.>member-name<option(s)>;
 The CPORT procedure
EXCLUDE SAS file(s) | catalog entry(s)</ writes SAS data sets, SAS
MEMTYPE=mtype></ catalogs, or SAS data
ENTRYTYPE=entry-type>; libraries to sequential file
SELECT SAS file(s) | catalog entry(s) </
MEMTYPE=mtype></ formats (transport files).
ENTRYTYPE=entry-type>;
TRANTAB NAME=translation-table-
name  Extension of the
<option(s)>; Transport files is .xpt

libname source 'SAS-data-library';


filename tranfile 'transport-file' host-option(s)-for-file-characteristics;
proc cport library=source file=tranfile memtype=catalog;
proc cport catalog=source.finance file=tranfile
after='09sep1996'd;
trantab name=ttable1 type=(format);
run;

SAS Techies 2009 11/02/21 18


PROC CIMPORT destination=libref |  The CIMPORT procedure
<libref.>member-name <option(s)>;
imports a transport file that
EXCLUDE SAS file(s) | catalog entry(s)</
MEMTYPE=mtype></
was created (exported) by the
ENTRYTYPE=entry-type>; CPORT procedure.
SELECT SAS file(s) | catalog entry(s)</
MEMTYPE=mtype></
ENTRYTYPE=entry-type>;
 PROC CIMPORT (only created
by Proc CPort) restores the
transport file to its original
form as a SAS catalog, SAS
data set, or SAS data library.

libname newlib 'SAS-data-library';


filename trans2 'transport-file' host-option(s)-for-file-
characteristics;
proc cimport catalog=newlib.finance infile=trans2;
select loan.pmenu loan.scl;
run;
SAS Techies 2009 11/02/21 19
PROC COMPARE <option(s)>;  The COMPARE procedure
BY <DESCENDING> variable-1 compares the contents of two
<...<DESCENDING> variable-n> SAS data sets, selected variables
<NOTSORTED>; in different data sets, or
ID <DESCENDING> variable-1 variables within the same data
<...<DESCENDING> variable-n> set.
<NOTSORTED>;
VAR variable(s);
 PROC COMPARE generates the
WITH variable(s); following information about the
two data sets that are being
compared:
◦ whether matching variables have
different values
◦ whether one data set has more
observations than the other
proc compare base=proclib.one ◦ what variables the two data sets
have in common
compare=proclib.two nosummary; ◦ how many variables are in one
var gr1; with gr2; data set but not in the other
◦ whether matching variables have
title 'Comparison of Variables in Different Data different formats, labels, or types.
Sets'; ◦ a comparison of the values of
matching observations.
run;

SAS Techies 2009 11/02/21 20


PROC IMPORT  The IMPORT procedure
DATAFILE="filename" | reads data from an
TABLE="tablename" external data source and
OUT=<libref.>SAS-data- writes it to a SAS data
set <(SAS-data-set- set.
options)>
<DBMS=identifier>  External data sources can
<REPLACE> ; include Microsoft Access
<data-source-statement(s);> Database, Excel files,
Lotus spreadsheets, and
delimited external files
proc import (in which columns of data
datafile='c:\Myfiles\Class.xl values are separated by a
s' delimiter such as a blank,
out=work.femaleclass comma, or tab).
(where=(sex='F'));
run;
 Unix SAS does not read
Excel, MS Access files….
Only .csv or tab
delimited.

SAS Techies 2009 11/02/21 21


PROC EXPORT  The EXPORT procedure
DATA=<libref.>SAS-data- reads data from a SAS data
set <(SAS-data-set- set and writes it to an
options)> external data source.
OUTFILE="filename"  External data sources can
OUTTABLE="tablename" include Microsoft Access
<DBMS=identifier> Database, Excel files, Lotus
<REPLACE>; <data-source- spreadsheets, and delimited
statement(s);> external files (in which
columns of data values are
separated by a delimiter
proc export such as a blank, comma, or
data=myfiles.grades1 tab).
dbms=excel2000  Unix SAS does not write to
Excel, MS Access files….
outfile='c:\Myfiles\Grades.x Only .csv or tab delimited.
ls';
sheet=Grades1;
run;

SAS Techies 2009 11/02/21 22


 PROC PRINTTO  The PRINTTO procedure
defines destinations for
To do this Use this option SAS procedure output
provide a description for a SAS log
or procedure output stored in a
LABEL=
and for the SAS log. By
SAS catalog entry
default, SAS procedure
output and the SAS log
route the SAS log to a permanent LOG=
external file or SAS catalog entry
combine the SAS log and LOG= and PRINT= are routed to the default
procedure output into a single file with same destination
replace the file instead of NEW
procedure output file and
appending to it the default SAS log file
route procedure output to a
permanent external file or SAS
PRINT=
for your method of
catalog entry or printer.
operation.

SAS Techies 2009 11/02/21 23


options nodate pageno=1 linesize=80 pagesize=60
source;
proc printto log=‘c:\temp.txt'; run;
data numbers;
input x y z;
datalines;
14.2 25.2 96.8
10.8 51.6 96.8
;

proc printto print='output-file' new; run;

proc print data=numbers;


title 'Listing of NUMBERS Data Set';
run;

SAS Techies 2009 11/02/21 24


PROC RANK <option(s)>; ◦ The RANK procedure
BY <DESCENDING> variable- computes ranks for one
1 or more numeric
<...<DESCENDING> variables across the
variable-n> observations of a SAS
<NOTSORTED>; data set and outputs
VAR data-set-variables(s); the ranks to a new SAS
RANKS new-variables(s); data set. PROC RANK
by itself produces no
printed output.

SAS Techies 2009 11/02/21 25


options nodate pageno=1 linesize=80 pagesize=60;
data elect;
input Candidate $ 1-11 District 13 Vote 15-18 Years 20;
datalines;
Cardella 1 1689 8
Latham 1 1005 2
Smith 1 1406 0
Walker 1 846 0
;
proc rank data=elect out=results ties=low descending;
by district;
var vote years;
ranks VoteRank YearsRank;
run;

SAS Techies 2009 11/02/21 26


PROC SUMMARY <option(s)> <statistic-
 The SUMMARY procedure
keyword(s)>; provides data summarization
BY <DESCENDING> variable- tools that compute descriptive
1<...<DESCENDING> variable-n> statistics for variables across all
<NOTSORTED>; observations or within groups of
CLASS variable(s) </ option(s)>; observations.
FREQ variable;
ID variable(s);
OUTPUT <OUT=SAS-data-set><output-
 The SUMMARY procedure is very
statistic-specification(s)> similar to the MEANS procedure
TYPES request(s); except for --
VAR variable(s)</ WEIGHT=weight-variable>;
WAYS list; WEIGHT variable; ◦ By default, PROC SUMMARY
produces no display output,
Proc summary data=some; but PROC MEANS does
Output Out=something (drop=_freq_ _type_)
sum=total;
produce display output.
By year; ◦ If you omit the VAR statement,
Var Trx; then PROC SUMMARY
Run;
produces a simple count of
observations, whereas PROC
MEANS tries to analyze all the
numeric variables that are not
listed in the other statements

SAS Techies 2009 11/02/21 27


PROC TRANSPOSE <DATA=input-data-set>  The TRANSPOSE procedure
<LABEL=label> <LET>
<NAME=name> <OUT=output-data-set> creates an output data set by
<PREFIX=prefix>; restructuring the values in a SAS
BY <DESCENDING> variable-1 data set, transposing selected
<...<DESCENDING> variable-n> variables into observations.
<NOTSORTED>;
COPY variable(s);
ID variable;
 If no var statement then
IDLABEL variable; transposes All Variables.
VAR variable(s);
 The TRANSPOSE procedure can
Proc transpose data= some out=something often eliminate the need to write
prefix=sm;
By CID;
a lengthy DATA step to achieve
Var TRx;
the same result.
Id yrmo;
Run;  Further, the output data set can
be used in subsequent DATA or
PROC steps for analysis,
reporting, or further data
manipulation.

SAS Techies 2009 11/02/21 28


 We will cover this at a later
date!!  The TEMPLATE procedure enables you to
customize the appearance of your SAS
 What it does? We can develop a output. For example, you can create,
template that we can apply to extend, or modify existing definitions for
various types of output:
enhance the appearance of an ◦ styles
listing output. Adjusting the ◦ tables
header, width, colors… similar ◦ columns
to what a proc report call ◦

headers
footers
define statement highlighting ◦ tagsets
can do.
 ODS then uses these definitions to produce
formatted output. You can also use the
TEMPLATE procedure to navigate and
manage the definitions stored in templates
stores. Here are some tasks that you can
do with PROC TEMPLATE:
◦ edit an existing definition
◦ create links to an existing definition
◦ change the location where you write new
definitions
◦ search for existing definitions
◦ view the source code of a definition

SAS Techies 2009 11/02/21 29


◦ The DATASETS procedure is a utility
procedure that manages your SAS files.
PROC DATASETS <option(s)>; With PROC DATASETS, you can
AGE current-name related-SAS-file(s)  copy SAS files from one SAS library to
APPEND BASE=<libref.>SAS-data-set another
<DATA=<libref.>SAS-data-set>  rename SAS files
<FORCE>;
 repair SAS files
AUDIT SAS-file <(SAS-password)>; INITIATE
<AUDIT_ALL=NO|YES<GENNUM= integer>)>;  delete SAS files
SUSPEND|RESUME| TERMINATE;  list the SAS files that are contained in a
CHANGE old-name-1=new-name-1 SAS library
CONTENTS<option(s)>;  list the attributes of a SAS data set,
COPY OUT=libref-1 <DATECOPY> <FORCE> such as the date when the data was last
<IN=libref-2> modified, whether the data is
EXCLUDE SAS-file(s) compressed, whether the data is
indexed, and so on
SELECT SAS-file(s)
 manipulate passwords on SAS files
DELETE SAS-file(s)
 append SAS data sets
EXCHANGE name-1=other-name-1
 modify attributes of SAS data sets and
MODIFY SAS-file <(option(s))>
variables within the data sets
FORMAT variable-list-1 <format-1>  create and delete indexes on SAS data
IC CREATE <constraint-name=> constraint sets
IC DELETE constraint-name(s)| _ALL_;  create and manage audit files for SAS
IC REACTIVATE foreign-key-name data sets
INDEX CENTILES index(s)  create and delete integrity constraints
INDEX CREATE index-specification(s) on SAS data sets.
INDEX DELETE index(s) | _ALL_;
INFORMAT
LABEL variable-1=<'label-1'|' '>
RENAME old-name-1=new-name-1
REPAIR SAS-file(s)
SAVE SAS-file(s)

SAS Techies 2009 11/02/21 30


options pagesize=40 linesize=80 nodate pageno=1 source;
libname health 'SAS-data-library';

proc datasets library=health nolist;


modify group (label='Test Subjects' read=green
sortedby=lname);
index create vital=(birth salary) / nomiss unique;
informat birth date7.;
format birth date7.;
label salary='current salary excluding bonus';
modify oxygen;
rename oxygen=intake;
label intake='Intake Measurement';
quit;

SAS Techies 2009 11/02/21 31


 The only difference between the APPEND and
many other procedures and the APPEND (and
similar) statements in PROC DATASETS is –

the default for libref in the BASE= and DATA=


arguments. For PROC APPEND, the default is
either WORK or USER. For the APPEND
statement, the default is the libref of the
procedure input library.

SAS Techies 2009 11/02/21 32


 CATALOG  RUN-group processing
 DATASETS enables you to submit a
PROC step with a RUN
 PLOT statement without ending
 PMENU the procedure. You can
 TRANTAB continue to use the
 GCHART procedure without
issuing another PROC
statement.

 To end the procedure,


use a RUN CANCEL or a
QUIT statement.

SAS Techies 2009 11/02/21 33

You might also like