SAS for Data Management and Analysis
Other Useful
Character and
Numeric Functions
Other Useful Character Functions
Function
Purpose
RIGHT(string)
Right aligns a character expression.
LEFT(string)
Left aligns a character expression.
UPCASE(string)
Converts
Accumulating Totals for Groups
1
Define First. and Last. processing.
Calculate an accumulating total for groups of data.
Use a subsetting IF statement to output selected
observations.
2
orion.specialsals
The Salary variable represents the portion of the e
Directing Output to External Files
1
Objectives
Direct output to ODS destinations by using
ODS statements.
Specify a style definition by using the STYLE= option.
Create ODS files that can be opened in Microsoft Excel.
2
Output Delivery System
LISTING
HTML
Creating an Accumulating Total Variable
1
A retail manager for Orion Star Sportswear has asked to see her
departments daily sales for April, as well as a month-to-date total for
each day.
Create a new data set, mnthtot, that includes the month-to-date
tot
Subsetting and Grouping Observations
1
Display selected observations in reports by using the WHERE
statement.
Display groups of observations in reports by using the BY
statement.
2
The WHERE Statement (Review)
For subsetting observations in a report, the
Using Global Statements
1
Objectives
Identify SAS statements that are used with most reporting procedures.
Enhance reports by using SAS system options.
Enhance reports by adding titles and footnotes.
Add dates and times to titles. (Self-Study)
2
Creating
Adding Labels and Formats
1
Objectives
Display descriptive column headings using the
LABEL statement.
Display formatted values using the FORMAT statement.
2
Labels anddisplaying reports,(Review)
Formats
When
a label changes the appearance of a variable
Merging Data Sets with Non-Matches
1
Control the observations in the output data set by
using the IN= option.
Output to multiple data sets using the IN= option
and the OUTPUT statement.
2
Create example data
data EmpsAU;
input First $ Gender $ EmpID ;
dat
The TABULATE Procedure
PROC TABULATE DATA=SASdataet <options>;
d s
PROC TABULATE DATA=SAS ataset <options>;
CLASS classificationvariable(s);
v
CLASS classificationariable(s);
VAR analysis-variable(s);
VAR analysis-variable(s);
TABLE
pageexpression,
e
TABL
SAS for Data Management and Analysis
Proc Means
The MEANS Procedure
PROC MEANS DATA=SASdataet <statistic(s)> <option(s)>;
d s
PROC MEANS DATA=SAS ataset <statistic(s)> <option(s)>;
VAR analysis-variable(s);
VAR analysis-variable(s);
CLASS classification-v
Combining SAS Data Sets
Introduction to Combining Data Sets
Appending a Data Set
Concatenating Data Sets
Merging Data Sets One-to-One
Merging Data Sets One-to-Many
Merging Data Sets with Non-Matches
1
Methods for combining
SAS data sets
2
Proc
Sort
The SO
SAS for Data Management and Analysis
Processing Data Iteratively
Do Loop Processing
Example
An employee wants to compare the
interest for yearly versus quarterly compounding on
a $50,000 investment made for one year at 4.5
percent interest.
How much money
SAS for Data Management and Analysis
Converting Variable Type
A firm has just acquired a small marketing firm
and needs to convert the firms personnel
data into a data set that can be easily
transferred into their HR system.
%include "c:\clearall.sas";
Li
Producing Summary Reports
Using the FREQ Procedure
The FREQ Procedure
Produce one-way and two-way frequency
tables with the FREQ procedure.
Enhance frequency tables with options.
The OUT= option in the TABLES and
OUTPUT statements.
PROC FREQ DATA=SASdatae
data lucky13;
do day = '01jan2015'd to '31dec2015'd by 1;
if trim(left(put(day,downame.)='Friday' and
put(day,day.)=13 then output;
end;
run;
proc print data=lucky13;
format day date9.;
run;
SAS for Data Management and Analysis
Manipulating Numeric Values
SAS functions to truncate numeric values.
SAS functions to compute descriptive
statistics of numeric values.
Truncation Functions
ROUND
CEIL
FLOOR
INT
The ROUND Function
NewVar=ROUND(arg
SAS for Data Management and Analysis
Enhancing Reports
Using Global Statements
Adding Labels and Formats
Creating User-Defined Formats
Subsetting and Grouping Observations
Directing Output to External Files
Creating Reports
SAS Procedures
for Creating
Rep
SAS for Data Management and Analysis
Using Arrays to
Restructure Data
proc contents
data=tmp.chdagesbp;
run;
proc print data=tmp.chdagesbp (obs=5);
var age:;
run;
proc print data=tmp.chdagesbp (obs=5);
var spf:;
run;
proc print data=tmp.chdagesbp (obs=5);
Manipulating Character Values
Example Create a List of Charities
Here is a sketch of the desired output:
Charity Names and ID Codes
ID
AQI
CCI
CNI
Name
Aquamissions International
Cancer Cures, Inc.
Conserve Nature, Inc.
The Biz_List data set
libname sasda
SAS for Data Management and Analysis
Transforming Data with SAS
Functions - Introduction
SAS Functions
Array
Character
Date And Time
Descriptive Statistics
Financial
Mathematical
Probability
Random Number
Trigonometric
Special
State and ZIP Code
Syntax fo
Two simple data sets
title "Study1";
proc print data=tmp.study1;
run;
title "Study2";
proc print data=tmp.study2;
run;
title;
Create a data set containing only males,
method 1
data males;
set tmp.study1 tmp.study2;
if male;
run;
proc print data=males;
run
Fundamentals of Biostatistics
Four Statistical Functions
Introduction to Simulation with the Data Step
The PDF Function
PDF (dist,quantile<,parm-1, . ,parm-k> )
title;
data pdf;
do x = -3 to 3 by 0.1;
y = pdf("Normal", x);
output;
end;
run;
proc sgplot da
SAS for Data Management and Analysis
Arrays
Array Processing
Arrays often simplify programs:
perform repetitive calculations
create many variables with the same attributes
read data
compare variables
perform a table lookup
SAS Arrays
Temporary grouping of
Merging Data Sets One-to-Many
1
Create PhoneHW SAS data set.
data PhoneHW;
input EmpID Type $ Phone
datalines;
121150 Home +61(2)5555-1793
121151 Home +61(2)5555-1849
121152 Home +61(2)5555-1665
;
run;
proc print data=PhoneHw;
run;
$15. @;
121150 Work +61
Merging Data Sets One-to-One
Merging can match on position or by a common variable(s)
1
Prepare data sets for merging using the SORT procedure.
Merge SAS data sets one-to-one based on a common variable by using
the MERGE and BY statements in a DATA step.
Concatenating Data Sets
With appending, the base data set was not read so the
descriptor portion could not change. That is not the
case with concatenating.
1
Concatenate two or more SAS data sets by using
the SET statement in a DATA step.
Change the names
SAS for Data Management and Analysis
SAS Programs
SAS Programs
A SAS program is a sequence of steps that the user
submits for execution.
Raw
Raw
Data
Data
DATA steps are typically used to create SAS
data sets.
DATA
DATA
Step
Step
SAS
Data
Set
SAS
Data
Set