SlideShare a Scribd company logo
SAS® Cheat Sheet
SAS Language
ATTRIB varn <LENGTH=’varn-length’> <LABEL=’varn-label’>
<FORMAT=varn-format.> <INFORMAT=varn-informat.>;
Associates a format, informat, label, and/or length with one
or more variables
CARDS or CARDS4 | DATALINES or DATALINES4
Indicates that data lines follow (suffix of 4 if data has ‘;’s).
DATA <dsetn <(dset-optionsn)>>;
Begins a DATA step and provides names for any output
SAS data sets. See Data Set Options for options that are
available in the DATA statement.
DO index-var=start_value TO end_value <BY step>;
DO UNTIL (expression);
DO WHILE (expression);
Groups a set of statements as a single unit. Note that
UNTIL conditions are evaluated at the end of the loop and
thus execute at least once.
FILE filename <options>;
Specifies the current output file for PUT statements.
Options include:
MOD output is appended to an existing file.
OLD output overwrites an existing file.
IF expression THEN statement; .... <ELSE> statement;
SAS evaluates the expression in an IF statement to
produce a result that is either non-zero, zero, or missing. If
result >0 then TRUE, else FALSE.
INFILE filename <options>;
Specifies an external file to read with an INPUT statement.
Options include:
DELIMITER|DLM= delimiters
Specifies a delimiter for list input.
LENGTH= variable
Names a variable that SAS sets to the length of the
current input line.
INPUT var<=> <$> startcol <-endcol> <.dec> <@ | @@>;
INPUT <pointer-control> variable informat. <@ | @@>;
INPUT <pointer-control> variable <$> <&> <@ | @@>;
Input records from the current input file, placing the values
into SAS variables.
MERGE ds1 <(doptions)> <... dsn<(doptions)>> <END=var>;
Joins observations from two or more SAS data sets into
single observations.
OUTPUT<data-set-name(s)>;
Writes the current observation to a SAS data set.
PUT var<=> <$> startcol <-endcol> <.dec> <@ | @@>;
PUT <pointer-control> <”text”|variable format.> <@ | @@>;
Writes variable values and/or text to the output line.
RETAIN variablen <initial-valuen>;
Causes a variable to retain its value from one iteration of
the data step to the next.
SET <data-set(s) <(data-set-options(s)>> <POINT=varname>
<NOBS=varname> <END=varname>;
Reads observations from one or more data sets.
Sum: variable+expression
Adds the result of an expression to an accumulator var.
TITLE <n> <”text”>;
Specifies title lines for SAS output. n specifies the relative
line number with n being between 1 and 10.
WHERE where-expression;
Selects observations from SAS data sets that meet a
particular condition that is true.
SAS Data Set Options
DROP=variable(s) Excludes variables from processing.
FIRSTOBS=n Specifies the first observation to process
IN=variable Creates and names a variable that indicates
whether the data set contributed data to the current
observation.
KEEP=variable(s) Selects variables for processing.
LABEL='label' Specifies a label for a SAS data set
OBS=n Specifies the first n observations to process
POINT=variable Direct observation number variable
RENAME=(oldname1=newname1 <...oldnamen=newnamen>)
Changes the name of a variable.
WHERE=(expression1 <logical-operator expressionn>)
Selects observations from a SAS data set that meet
certain conditions before SAS brings them into the DATA
or PROC step for processing.
SAS Functions
BYTE(n) Returns one character in the ASCII or EBCDIC
collating sequence where n is an integer representing a
specific ASCII or EBCDIC character
COMPBL(source) Removes multiple blanks from a character
string
COMPRESS(source<,characters-to-remove>)
Removes specific characters from a character string
DATE() Returns the current date as a SAS date value
DATEPART(datetime) Extracts the date from a SAS
datetime value
DATETIME() Returns the current date and time of day
DAY(date) Returns the day of the month from a SAS date
value
HMS(hour,minute,second) Returns a SAS time value from
hour, minute, and second
INDEX(source,excerpt) Searches the source for the
character string specified by the excerpt
LEFT(argument) Left-aligns a SAS character string
LENGTH(argument) Returns the length of an argument
LOWCASE(argument) Converts all letters in an argument to
lowercase
MAX(argument,argument, ...) Returns the largest value of
the numeric arguments
MDY(month,day,year) Returns a SAS date value from
month, day, and year
MIN(argument,argument, ...) Returns the smallest value of
the numeric arguments
MISSING(argument) Indicates whether the argument
contains a missing value
MOD(argument1, argument2) Returns the remainder
MONTH(date) Returns the month from a SAS date value
RANK(x) Returns the position of a character x in the ASCII
or EBCDIC collating sequence
REPEAT(‘character-expression’,n) Repeats a character
expression n+1 times.
RIGHT(argument) Right-aligns a character expression
ROUND(argument,round-off-unit) Rounds to the nearest
round-off unit
SCAN(argument,n<,delimiters>) Returns a given word from
a character expression
SUBSTR(argument,position<,n>) Extracts a substring from
an argument.
TIME() Returns the current time of day
TIMEPART(datetime) Extracts a time value from a SAS
datetime value
TODAY() Returns the current date as a SAS date value
TRANSLATE(source,to,from) Replaces specific characters in
a character expression
SUM(argument,argument, ...) Returns the total value of the
numeric arguments
TRIM(argument) Takes the argument and removes any
trailing blanks.
UPCASE(argument) Converts all letters in an argument to
uppercase
WEEKDAY(date) Returns the day of the week from a SAS
date value
YEAR(date) Returns the year from a SAS date value
SAS Formats
w.d standard numeric
COMMAw.d writes numeric values with commas and
decimal points
Zw.d print leading zeros
$w. writes standard character data
$CHARw. writes standard character data (including
leading blanks)
$VARYINGw. Writes character data of varying length
SAS Informats
w.d Reads standard numeric data
datew. Reads date values (ddmmmyy)
$w. Reads standard character data
$VARYINGw. Reads character data of varying length
Compliments of:
David Franklin
New Hampshire, USA
Tel/Fax +1(603) 262-9160 Cell +1(603) 275-6809
Email 100316.3451@compuserve.com
Google “Franklin SAS”
http://ourworld.compuserve.com/homepages/dfranklinuk
Release 1.2b ©MMVII
SAS® Cheat Sheet
SAS Procedures
PROC COMPARE <BASE=dset> <COMPARE=dset>;
BY variable(s);
ID variable(s);
VAR variable(s);
PROC DATASETS <LIBRARY=libref> <MEMTYPE=(m-list)>
<DETAILS|NODETAILS> <KILL>
<NOLIST>;
APPEND BASE=dset <DATA=dset> <FORCE>;
CHANGE old-namen=new-namen </MEMTYPE=(m-list);
CONTENTS <DATA=<libref.>member> <DIRECTORY>
<MEMTYPE=(m-list)> <NODS>
<VARNUM> <NOPRINT> <OUT=dset>;
COPY OUT=libref <IN=libref> <MEMTYPE=(m-list)>
<MOVE>;
EXCLUDE member-list </MEMTYPE=mtype>;
SELECT member-list </MEMTYPE=mtype>;
DELETE member-list </ MEMTYPE=mtype>;
MODIFY member-name <(<LABEL=’data-set-label’|’ ‘>
<SORTEDBY=sort-information>)>;
FORMAT variable-format-name.;
INDEX CREATE variable </<UNIQUE> <NOMISS>>;
INDEX CREATE index=(variable-list) </<UNIQUE>
<NOMISS>>;
INDEX DELETE index-list;
LABEL variable=’label-text’;
RENAME variablen=new-variablen;
QUIT;
where
m-list one or more of the member types that
processing should be restricted to.
member-list list of members in the directory to
process.
mtype restricts processing to one member type.
PROC EXPORT DATA=<libref.>dset
OUTFILE="filename" <REPLACE>;
PROC IMPORT DATAFILE="filename"
OUT=<libref.>dset <REPLACE>;
The following filetypes are the most commonly used and
supported within filename by SAS:
filename.XLS (Microsoft Excel)
filename.TXT (tab delimited)
filename.CSV (comma separated value)
PROC FORMAT <CNTLIN=dset>
<CNTLOUT=dset>
<LIBRARY=libref<.catalog>>;
INVALUE <$>name <value-range-set(s)>;
PICTURE name <...value-range-set <(picture-option(s))>>;
VALUE <$>name <value-range-set>;
where
picture-options The following options are useful:
ROUND NOEDIT
PREFIX= FILL=
PROC FREQ <DATA=dset>
<ORDER=DATA|EXTERNAL|FREQ|INTERNAL>;
BY <DESCENDING> varn;
TABLES requests </tables-options>;
where
requests one or more variable names joined by
asterisks that specify the form of the
generated tables, e.g. A*B
tables-options Can be one or more of the following:
LIST MISSING
NOPRINT OUT=SAS-data-set
OUTPCT SPARSE
PROC MEANS <DATA=dset> <DESCENDING>
<MISSING> <NOPRINT> <NWAY>
<ORDER=DATA|EXTERNAL|FREQ|
INTERNAL>
<statistic-list>;
VAR variable-list;
CLASS variable-list;
OUTPUT <OUT=dset> <out-statistic>;
where
statistic-list Can be one or more of the following:
N, NMISS, MIN, MAX, RANGE,
MEDIAN, SUM, MEAN, VAR, STD,
Q1, Q3, T
out-statistic Specifies the statistics in the output and
also names the variable(s) that contain
the results.
PROC REPORT <DATA=dset> <HEADLINE> <HEADSKIP>
<NOWINDOWS> <SPACING=number>;
COLUMNS <report-item1, <., report-itemn>>
(`header1 ' < . `headern '> report-item(s) );
DEFINE report-item / <usage> <define-options>;
COMPUTE <BEFORE|AFTER> report-item;
LINE <item item-format | 'text' | pointer-control>;
ENDCOMP;
BREAK BEFORE|AFTER break-variable </b-option(s)>;
QUIT;
where
report-item name or alias (established in the
COLUMN statement) of the data set or
computed variable, or statistic to define
usage Either ACROSS, ANALYSIS,
COMPUTED, DISPLAY, GROUP,
ORDER
define-options The following options are available:
FORMAT=format ORDER=
SPACING= WIDTH=
DESCENDING FLOW
NOPRINT CENTER
LEFT RIGHT
COLOR= ‘column-header’
b-options These include:
SKIP PAGE
PROC SORT <DATA=dset> <OUT=dset>
<NODUPKEY|NODUPS>;
BY <DESCENDING> variable-list;
PROC TRANSPOSE <DATA=dset> <OUT=dset>;
BY <DESCENDING> variable-list;
ID variable;
VAR variable1 … variablen;
Macro Language
%DO macro-var=start_value %TO end_value <%BY step>;
Executes a section of a macro repetitively based on the
value of an index variable
%DO %WHILE (expression);
Executes a section of a macro repetitively while a condition
is true
%DO %UNTIL (expression);
Executes a section of a macro repetitively until a condition
is true
%GLOBAL macro-variable(s);
Creates macro variables that are available during the
execution of an entire SAS session
%IF expression %THEN action; <%ELSE action;>
Conditionally process a portion of a macro
%LENGTH (character string | text expression)
Returns the length of a string
%LET macro-variable =<value>;
Creates a macro variable and assigns it a value
%MACRO m-name (<pp1><…,ppn><kp1=value<..<kpn=v>);
Begins a macro definition
%MEND <macro-name>;
Ends a macro definition
%SCAN(argumentn<,delimiters>)
Search for a word that is specified by its position in a string
%SUBSTR(argument,position<,length>)
Produce a substring of a character string
%UPCASE(character string | text expression)
Convert values to uppercase
Macro Quoting
%QUOTE | %NRQUOTE and %BQUOTE | %NRBQUOTE
Mask special characters and mnemonic operators in a
resolved value at macro execution
%STR | %NRSTR
Mask special characters and mnemonic operators in
constant text at macro compilation
%SUPERQ
Masks special characters/mnemonic operators at macro
execution but prevents further resolution of the value.
Compliments of:
David Franklin
New Hampshire, USA
Tel/Fax +1(603) 262-9160 Cell +1(603) 275-6809
Email 100316.3451@compuserve.com
Google “Franklin SAS”
http://ourworld.compuserve.com/homepages/dfranklinuk
Release 1.2b ©MMVII

More Related Content

What's hot

SAS Functions
SAS FunctionsSAS Functions
SAS Functions
guest2160992
 
Understanding SAS Data Step Processing
Understanding SAS Data Step ProcessingUnderstanding SAS Data Step Processing
Understanding SAS Data Step Processing
guest2160992
 
Introduction to SAS
Introduction to SASIntroduction to SAS
Introduction to SAS
izahn
 
Sas
SasSas
Arrays in SAS
Arrays in SASArrays in SAS
Arrays in SAS
guest2160992
 
Sas Plots Graphs
Sas Plots GraphsSas Plots Graphs
Sas Plots Graphs
guest2160992
 
SAS Programming Notes
SAS Programming NotesSAS Programming Notes
SAS Programming Notes
Gnana Murthy A
 
SAS BASICS
SAS BASICSSAS BASICS
SAS BASICS
Bhuwanesh Rawat
 
Where Vs If Statement
Where Vs If StatementWhere Vs If Statement
Where Vs If Statement
Sunil Gupta
 
SAS basics Step by step learning
SAS basics Step by step learningSAS basics Step by step learning
SAS basics Step by step learning
Venkata Reddy Konasani
 
Proc report
Proc reportProc report
Proc report
eagebhart
 
Introduction to SAS Data Set Options
Introduction to SAS Data Set OptionsIntroduction to SAS Data Set Options
Introduction to SAS Data Set Options
Mark Tabladillo
 
Sas Functions INDEX / INDEXC / INDEXW
Sas Functions INDEX / INDEXC / INDEXWSas Functions INDEX / INDEXC / INDEXW
Sas Functions INDEX / INDEXC / INDEXW
THARUN PORANDLA
 
INTRODUCTION TO SAS
INTRODUCTION TO SASINTRODUCTION TO SAS
INTRODUCTION TO SAS
Bhuwanesh Rawat
 
Basics of SAS
Basics of SASBasics of SAS
Basics of SAS
Taddesse Kassahun
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
Ram Sagar Mourya
 
Sas practice programs
Sas practice programsSas practice programs
Sas practice programs
gowthami marreddy
 
Learning sql from w3schools
Learning sql from w3schoolsLearning sql from w3schools
Learning sql from w3schools
farhan516
 
String function in my sql
String function in my sqlString function in my sql
String function in my sql
knowledgemart
 

What's hot (20)

SAS Functions
SAS FunctionsSAS Functions
SAS Functions
 
Understanding SAS Data Step Processing
Understanding SAS Data Step ProcessingUnderstanding SAS Data Step Processing
Understanding SAS Data Step Processing
 
Introduction to SAS
Introduction to SASIntroduction to SAS
Introduction to SAS
 
Sas
SasSas
Sas
 
Arrays in SAS
Arrays in SASArrays in SAS
Arrays in SAS
 
Sas Plots Graphs
Sas Plots GraphsSas Plots Graphs
Sas Plots Graphs
 
SAS Programming Notes
SAS Programming NotesSAS Programming Notes
SAS Programming Notes
 
SAS BASICS
SAS BASICSSAS BASICS
SAS BASICS
 
Where Vs If Statement
Where Vs If StatementWhere Vs If Statement
Where Vs If Statement
 
SAS basics Step by step learning
SAS basics Step by step learningSAS basics Step by step learning
SAS basics Step by step learning
 
Proc report
Proc reportProc report
Proc report
 
Introduction to SAS Data Set Options
Introduction to SAS Data Set OptionsIntroduction to SAS Data Set Options
Introduction to SAS Data Set Options
 
Sas Functions INDEX / INDEXC / INDEXW
Sas Functions INDEX / INDEXC / INDEXWSas Functions INDEX / INDEXC / INDEXW
Sas Functions INDEX / INDEXC / INDEXW
 
INTRODUCTION TO SAS
INTRODUCTION TO SASINTRODUCTION TO SAS
INTRODUCTION TO SAS
 
Basics of SAS
Basics of SASBasics of SAS
Basics of SAS
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
 
SAS Internal Training
SAS Internal TrainingSAS Internal Training
SAS Internal Training
 
Sas practice programs
Sas practice programsSas practice programs
Sas practice programs
 
Learning sql from w3schools
Learning sql from w3schoolsLearning sql from w3schools
Learning sql from w3schools
 
String function in my sql
String function in my sqlString function in my sql
String function in my sql
 

Viewers also liked

Clinical SAS Programming | SAS Training | Big Data | Hadoop | Business Analyt...
Clinical SAS Programming | SAS Training | Big Data | Hadoop | Business Analyt...Clinical SAS Programming | SAS Training | Big Data | Hadoop | Business Analyt...
Clinical SAS Programming | SAS Training | Big Data | Hadoop | Business Analyt...
Epochresearch
 
ADM Server
ADM ServerADM Server
Clinical sas programmer
Clinical sas programmerClinical sas programmer
Clinical sas programmerray4hz
 
Introduction to clinical sas programming
Introduction to clinical sas programmingIntroduction to clinical sas programming
Introduction to clinical sas programming
ray4hz
 
Intro to Data Science for Enterprise Big Data
Intro to Data Science for Enterprise Big DataIntro to Data Science for Enterprise Big Data
Intro to Data Science for Enterprise Big Data
Paco Nathan
 
Effective 15-minute presentations - Cheat Sheet
Effective 15-minute presentations - Cheat SheetEffective 15-minute presentations - Cheat Sheet
Effective 15-minute presentations - Cheat Sheet
Jan Schrage
 
Myths and Mathemagical Superpowers of Data Scientists
Myths and Mathemagical Superpowers of Data ScientistsMyths and Mathemagical Superpowers of Data Scientists
Myths and Mathemagical Superpowers of Data Scientists
David Pittman
 
Titan: The Rise of Big Graph Data
Titan: The Rise of Big Graph DataTitan: The Rise of Big Graph Data
Titan: The Rise of Big Graph Data
Marko Rodriguez
 
How to Interview a Data Scientist
How to Interview a Data ScientistHow to Interview a Data Scientist
How to Interview a Data Scientist
Daniel Tunkelang
 
Titan: Big Graph Data with Cassandra
Titan: Big Graph Data with CassandraTitan: Big Graph Data with Cassandra
Titan: Big Graph Data with Cassandra
Matthias Broecheler
 
A Statistician's View on Big Data and Data Science (Version 1)
A Statistician's View on Big Data and Data Science (Version 1)A Statistician's View on Big Data and Data Science (Version 1)
A Statistician's View on Big Data and Data Science (Version 1)
Prof. Dr. Diego Kuonen
 
Introduction to R for Data Mining
Introduction to R for Data MiningIntroduction to R for Data Mining
Introduction to R for Data Mining
Revolution Analytics
 
Big Data [sorry] & Data Science: What Does a Data Scientist Do?
Big Data [sorry] & Data Science: What Does a Data Scientist Do?Big Data [sorry] & Data Science: What Does a Data Scientist Do?
Big Data [sorry] & Data Science: What Does a Data Scientist Do?
Data Science London
 

Viewers also liked (14)

Clinical SAS Programming | SAS Training | Big Data | Hadoop | Business Analyt...
Clinical SAS Programming | SAS Training | Big Data | Hadoop | Business Analyt...Clinical SAS Programming | SAS Training | Big Data | Hadoop | Business Analyt...
Clinical SAS Programming | SAS Training | Big Data | Hadoop | Business Analyt...
 
ADM Server
ADM ServerADM Server
ADM Server
 
Clinical sas programmer
Clinical sas programmerClinical sas programmer
Clinical sas programmer
 
Introduction to clinical sas programming
Introduction to clinical sas programmingIntroduction to clinical sas programming
Introduction to clinical sas programming
 
Sas demo
Sas demoSas demo
Sas demo
 
Intro to Data Science for Enterprise Big Data
Intro to Data Science for Enterprise Big DataIntro to Data Science for Enterprise Big Data
Intro to Data Science for Enterprise Big Data
 
Effective 15-minute presentations - Cheat Sheet
Effective 15-minute presentations - Cheat SheetEffective 15-minute presentations - Cheat Sheet
Effective 15-minute presentations - Cheat Sheet
 
Myths and Mathemagical Superpowers of Data Scientists
Myths and Mathemagical Superpowers of Data ScientistsMyths and Mathemagical Superpowers of Data Scientists
Myths and Mathemagical Superpowers of Data Scientists
 
Titan: The Rise of Big Graph Data
Titan: The Rise of Big Graph DataTitan: The Rise of Big Graph Data
Titan: The Rise of Big Graph Data
 
How to Interview a Data Scientist
How to Interview a Data ScientistHow to Interview a Data Scientist
How to Interview a Data Scientist
 
Titan: Big Graph Data with Cassandra
Titan: Big Graph Data with CassandraTitan: Big Graph Data with Cassandra
Titan: Big Graph Data with Cassandra
 
A Statistician's View on Big Data and Data Science (Version 1)
A Statistician's View on Big Data and Data Science (Version 1)A Statistician's View on Big Data and Data Science (Version 1)
A Statistician's View on Big Data and Data Science (Version 1)
 
Introduction to R for Data Mining
Introduction to R for Data MiningIntroduction to R for Data Mining
Introduction to R for Data Mining
 
Big Data [sorry] & Data Science: What Does a Data Scientist Do?
Big Data [sorry] & Data Science: What Does a Data Scientist Do?Big Data [sorry] & Data Science: What Does a Data Scientist Do?
Big Data [sorry] & Data Science: What Does a Data Scientist Do?
 

Similar to Sas cheat

Stata cheat sheet: data transformation
Stata  cheat sheet: data transformationStata  cheat sheet: data transformation
Stata cheat sheet: data transformation
Tim Essam
 
Sas classes in mumbai
Sas classes in mumbaiSas classes in mumbai
Sas classes in mumbai
Vibrant Technologies & Computers
 
I need help with Applied Statistics and the SAS Programming Language.pdf
I need help with Applied Statistics and the SAS Programming Language.pdfI need help with Applied Statistics and the SAS Programming Language.pdf
I need help with Applied Statistics and the SAS Programming Language.pdf
Madansilks
 
DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6
YOGESH SINGH
 
BAS 150 Lesson 6 Lecture
BAS 150 Lesson 6 LectureBAS 150 Lesson 6 Lecture
BAS 150 Lesson 6 Lecture
Wake Tech BAS
 
Introducción al Software Analítico SAS
Introducción al Software Analítico SASIntroducción al Software Analítico SAS
Introducción al Software Analítico SAS
Jorge Rodríguez M.
 
Stata cheat sheet: data processing
Stata cheat sheet: data processingStata cheat sheet: data processing
Stata cheat sheet: data processing
Tim Essam
 
Introduction to sas
Introduction to sasIntroduction to sas
Introduction to sas
Ajay Ohri
 
98765432345671223Intro-to-PostgreSQL.ppt
98765432345671223Intro-to-PostgreSQL.ppt98765432345671223Intro-to-PostgreSQL.ppt
98765432345671223Intro-to-PostgreSQL.ppt
HastavaramDineshKuma
 
Database queries
Database queriesDatabase queries
Database queries
laiba29012
 
A Divine Data Comedy
A Divine Data ComedyA Divine Data Comedy
A Divine Data Comedy
Mike Harris
 
Cheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF CompleteCheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF Complete
TsamaraLuthfia1
 
Sql
SqlSql
Python Programming.pptx
Python Programming.pptxPython Programming.pptx
Python Programming.pptx
SudhakarVenkey
 
Mysqlppt
MysqlpptMysqlppt
MysqlpptReka
 
Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Stata Cheat Sheets (all)
Stata Cheat Sheets (all)
Laura Hughes
 
MS SQL Server 1
MS SQL Server 1MS SQL Server 1
MS SQL Server 1Iblesoft
 
Stata cheatsheet transformation
Stata cheatsheet transformationStata cheatsheet transformation
Stata cheatsheet transformation
Laura Hughes
 

Similar to Sas cheat (20)

Stata cheat sheet: data transformation
Stata  cheat sheet: data transformationStata  cheat sheet: data transformation
Stata cheat sheet: data transformation
 
Sas classes in mumbai
Sas classes in mumbaiSas classes in mumbai
Sas classes in mumbai
 
I need help with Applied Statistics and the SAS Programming Language.pdf
I need help with Applied Statistics and the SAS Programming Language.pdfI need help with Applied Statistics and the SAS Programming Language.pdf
I need help with Applied Statistics and the SAS Programming Language.pdf
 
DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6
 
Sas summary guide
Sas summary guideSas summary guide
Sas summary guide
 
BAS 150 Lesson 6 Lecture
BAS 150 Lesson 6 LectureBAS 150 Lesson 6 Lecture
BAS 150 Lesson 6 Lecture
 
Introducción al Software Analítico SAS
Introducción al Software Analítico SASIntroducción al Software Analítico SAS
Introducción al Software Analítico SAS
 
Stata cheat sheet: data processing
Stata cheat sheet: data processingStata cheat sheet: data processing
Stata cheat sheet: data processing
 
Introduction to sas
Introduction to sasIntroduction to sas
Introduction to sas
 
98765432345671223Intro-to-PostgreSQL.ppt
98765432345671223Intro-to-PostgreSQL.ppt98765432345671223Intro-to-PostgreSQL.ppt
98765432345671223Intro-to-PostgreSQL.ppt
 
Database queries
Database queriesDatabase queries
Database queries
 
A Divine Data Comedy
A Divine Data ComedyA Divine Data Comedy
A Divine Data Comedy
 
Cheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF CompleteCheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF Complete
 
Sql
SqlSql
Sql
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
 
Python Programming.pptx
Python Programming.pptxPython Programming.pptx
Python Programming.pptx
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Stata Cheat Sheets (all)
Stata Cheat Sheets (all)
 
MS SQL Server 1
MS SQL Server 1MS SQL Server 1
MS SQL Server 1
 
Stata cheatsheet transformation
Stata cheatsheet transformationStata cheatsheet transformation
Stata cheatsheet transformation
 

More from imaduddin91

07 a80102 groundwaterdevelopmentandmanagement
07 a80102 groundwaterdevelopmentandmanagement07 a80102 groundwaterdevelopmentandmanagement
07 a80102 groundwaterdevelopmentandmanagementimaduddin91
 
Remotesensingandgisapplications
RemotesensingandgisapplicationsRemotesensingandgisapplications
Remotesensingandgisapplicationsimaduddin91
 
R05410107 advancedfoundationengineering
R05410107 advancedfoundationengineeringR05410107 advancedfoundationengineering
R05410107 advancedfoundationengineeringimaduddin91
 
07 a80101 advanced structural design
07 a80101 advanced structural design07 a80101 advanced structural design
07 a80101 advanced structural designimaduddin91
 
07 a70401 remotesensingandgisapplications
07 a70401 remotesensingandgisapplications07 a70401 remotesensingandgisapplications
07 a70401 remotesensingandgisapplicationsimaduddin91
 
07 a70102 finite element methods in civil engineering
07 a70102 finite element methods in civil engineering07 a70102 finite element methods in civil engineering
07 a70102 finite element methods in civil engineeringimaduddin91
 
R05410103 remotesensingandgisapplications
R05410103 remotesensingandgisapplicationsR05410103 remotesensingandgisapplications
R05410103 remotesensingandgisapplicationsimaduddin91
 
R05410102 finiteelementmethodsincivilengineering
R05410102 finiteelementmethodsincivilengineeringR05410102 finiteelementmethodsincivilengineering
R05410102 finiteelementmethodsincivilengineeringimaduddin91
 
07 a60105 estimatingandcosting
07 a60105 estimatingandcosting07 a60105 estimatingandcosting
07 a60105 estimatingandcostingimaduddin91
 
07 a82101 advanced structural design
07 a82101  advanced structural design07 a82101  advanced structural design
07 a82101 advanced structural designimaduddin91
 
07 a80106 pavementanalysisanddesign
07 a80106 pavementanalysisanddesign07 a80106 pavementanalysisanddesign
07 a80106 pavementanalysisanddesignimaduddin91
 
07 a80104 watershedmanagement
07 a80104 watershedmanagement07 a80104 watershedmanagement
07 a80104 watershedmanagementimaduddin91
 
07 a80102 groundwaterdevelopmentandmanagement
07 a80102 groundwaterdevelopmentandmanagement07 a80102 groundwaterdevelopmentandmanagement
07 a80102 groundwaterdevelopmentandmanagementimaduddin91
 
07 a70110 remotesensingandgisapplications
07 a70110 remotesensingandgisapplications07 a70110 remotesensingandgisapplications
07 a70110 remotesensingandgisapplicationsimaduddin91
 
07 a70107 waterresourcessystemplanningandmanagement
07 a70107 waterresourcessystemplanningandmanagement07 a70107 waterresourcessystemplanningandmanagement
07 a70107 waterresourcessystemplanningandmanagementimaduddin91
 
07 a70102 finite element methods in civil engineering
07 a70102  finite element methods in civil engineering07 a70102  finite element methods in civil engineering
07 a70102 finite element methods in civil engineeringimaduddin91
 
07 a60105 estimatingandcosting
07 a60105 estimatingandcosting07 a60105 estimatingandcosting
07 a60105 estimatingandcostingimaduddin91
 
Statistical metods
Statistical metodsStatistical metods
Statistical metodsimaduddin91
 
Sas language reference concepts
Sas language reference  conceptsSas language reference  concepts
Sas language reference conceptsimaduddin91
 
Base 9.1 preparation guide
Base 9.1 preparation guideBase 9.1 preparation guide
Base 9.1 preparation guideimaduddin91
 

More from imaduddin91 (20)

07 a80102 groundwaterdevelopmentandmanagement
07 a80102 groundwaterdevelopmentandmanagement07 a80102 groundwaterdevelopmentandmanagement
07 a80102 groundwaterdevelopmentandmanagement
 
Remotesensingandgisapplications
RemotesensingandgisapplicationsRemotesensingandgisapplications
Remotesensingandgisapplications
 
R05410107 advancedfoundationengineering
R05410107 advancedfoundationengineeringR05410107 advancedfoundationengineering
R05410107 advancedfoundationengineering
 
07 a80101 advanced structural design
07 a80101 advanced structural design07 a80101 advanced structural design
07 a80101 advanced structural design
 
07 a70401 remotesensingandgisapplications
07 a70401 remotesensingandgisapplications07 a70401 remotesensingandgisapplications
07 a70401 remotesensingandgisapplications
 
07 a70102 finite element methods in civil engineering
07 a70102 finite element methods in civil engineering07 a70102 finite element methods in civil engineering
07 a70102 finite element methods in civil engineering
 
R05410103 remotesensingandgisapplications
R05410103 remotesensingandgisapplicationsR05410103 remotesensingandgisapplications
R05410103 remotesensingandgisapplications
 
R05410102 finiteelementmethodsincivilengineering
R05410102 finiteelementmethodsincivilengineeringR05410102 finiteelementmethodsincivilengineering
R05410102 finiteelementmethodsincivilengineering
 
07 a60105 estimatingandcosting
07 a60105 estimatingandcosting07 a60105 estimatingandcosting
07 a60105 estimatingandcosting
 
07 a82101 advanced structural design
07 a82101  advanced structural design07 a82101  advanced structural design
07 a82101 advanced structural design
 
07 a80106 pavementanalysisanddesign
07 a80106 pavementanalysisanddesign07 a80106 pavementanalysisanddesign
07 a80106 pavementanalysisanddesign
 
07 a80104 watershedmanagement
07 a80104 watershedmanagement07 a80104 watershedmanagement
07 a80104 watershedmanagement
 
07 a80102 groundwaterdevelopmentandmanagement
07 a80102 groundwaterdevelopmentandmanagement07 a80102 groundwaterdevelopmentandmanagement
07 a80102 groundwaterdevelopmentandmanagement
 
07 a70110 remotesensingandgisapplications
07 a70110 remotesensingandgisapplications07 a70110 remotesensingandgisapplications
07 a70110 remotesensingandgisapplications
 
07 a70107 waterresourcessystemplanningandmanagement
07 a70107 waterresourcessystemplanningandmanagement07 a70107 waterresourcessystemplanningandmanagement
07 a70107 waterresourcessystemplanningandmanagement
 
07 a70102 finite element methods in civil engineering
07 a70102  finite element methods in civil engineering07 a70102  finite element methods in civil engineering
07 a70102 finite element methods in civil engineering
 
07 a60105 estimatingandcosting
07 a60105 estimatingandcosting07 a60105 estimatingandcosting
07 a60105 estimatingandcosting
 
Statistical metods
Statistical metodsStatistical metods
Statistical metods
 
Sas language reference concepts
Sas language reference  conceptsSas language reference  concepts
Sas language reference concepts
 
Base 9.1 preparation guide
Base 9.1 preparation guideBase 9.1 preparation guide
Base 9.1 preparation guide
 

Sas cheat

  • 1. SAS® Cheat Sheet SAS Language ATTRIB varn <LENGTH=’varn-length’> <LABEL=’varn-label’> <FORMAT=varn-format.> <INFORMAT=varn-informat.>; Associates a format, informat, label, and/or length with one or more variables CARDS or CARDS4 | DATALINES or DATALINES4 Indicates that data lines follow (suffix of 4 if data has ‘;’s). DATA <dsetn <(dset-optionsn)>>; Begins a DATA step and provides names for any output SAS data sets. See Data Set Options for options that are available in the DATA statement. DO index-var=start_value TO end_value <BY step>; DO UNTIL (expression); DO WHILE (expression); Groups a set of statements as a single unit. Note that UNTIL conditions are evaluated at the end of the loop and thus execute at least once. FILE filename <options>; Specifies the current output file for PUT statements. Options include: MOD output is appended to an existing file. OLD output overwrites an existing file. IF expression THEN statement; .... <ELSE> statement; SAS evaluates the expression in an IF statement to produce a result that is either non-zero, zero, or missing. If result >0 then TRUE, else FALSE. INFILE filename <options>; Specifies an external file to read with an INPUT statement. Options include: DELIMITER|DLM= delimiters Specifies a delimiter for list input. LENGTH= variable Names a variable that SAS sets to the length of the current input line. INPUT var<=> <$> startcol <-endcol> <.dec> <@ | @@>; INPUT <pointer-control> variable informat. <@ | @@>; INPUT <pointer-control> variable <$> <&> <@ | @@>; Input records from the current input file, placing the values into SAS variables. MERGE ds1 <(doptions)> <... dsn<(doptions)>> <END=var>; Joins observations from two or more SAS data sets into single observations. OUTPUT<data-set-name(s)>; Writes the current observation to a SAS data set. PUT var<=> <$> startcol <-endcol> <.dec> <@ | @@>; PUT <pointer-control> <”text”|variable format.> <@ | @@>; Writes variable values and/or text to the output line. RETAIN variablen <initial-valuen>; Causes a variable to retain its value from one iteration of the data step to the next. SET <data-set(s) <(data-set-options(s)>> <POINT=varname> <NOBS=varname> <END=varname>; Reads observations from one or more data sets. Sum: variable+expression Adds the result of an expression to an accumulator var. TITLE <n> <”text”>; Specifies title lines for SAS output. n specifies the relative line number with n being between 1 and 10. WHERE where-expression; Selects observations from SAS data sets that meet a particular condition that is true. SAS Data Set Options DROP=variable(s) Excludes variables from processing. FIRSTOBS=n Specifies the first observation to process IN=variable Creates and names a variable that indicates whether the data set contributed data to the current observation. KEEP=variable(s) Selects variables for processing. LABEL='label' Specifies a label for a SAS data set OBS=n Specifies the first n observations to process POINT=variable Direct observation number variable RENAME=(oldname1=newname1 <...oldnamen=newnamen>) Changes the name of a variable. WHERE=(expression1 <logical-operator expressionn>) Selects observations from a SAS data set that meet certain conditions before SAS brings them into the DATA or PROC step for processing. SAS Functions BYTE(n) Returns one character in the ASCII or EBCDIC collating sequence where n is an integer representing a specific ASCII or EBCDIC character COMPBL(source) Removes multiple blanks from a character string COMPRESS(source<,characters-to-remove>) Removes specific characters from a character string DATE() Returns the current date as a SAS date value DATEPART(datetime) Extracts the date from a SAS datetime value DATETIME() Returns the current date and time of day DAY(date) Returns the day of the month from a SAS date value HMS(hour,minute,second) Returns a SAS time value from hour, minute, and second INDEX(source,excerpt) Searches the source for the character string specified by the excerpt LEFT(argument) Left-aligns a SAS character string LENGTH(argument) Returns the length of an argument LOWCASE(argument) Converts all letters in an argument to lowercase MAX(argument,argument, ...) Returns the largest value of the numeric arguments MDY(month,day,year) Returns a SAS date value from month, day, and year MIN(argument,argument, ...) Returns the smallest value of the numeric arguments MISSING(argument) Indicates whether the argument contains a missing value MOD(argument1, argument2) Returns the remainder MONTH(date) Returns the month from a SAS date value RANK(x) Returns the position of a character x in the ASCII or EBCDIC collating sequence REPEAT(‘character-expression’,n) Repeats a character expression n+1 times. RIGHT(argument) Right-aligns a character expression ROUND(argument,round-off-unit) Rounds to the nearest round-off unit SCAN(argument,n<,delimiters>) Returns a given word from a character expression SUBSTR(argument,position<,n>) Extracts a substring from an argument. TIME() Returns the current time of day TIMEPART(datetime) Extracts a time value from a SAS datetime value TODAY() Returns the current date as a SAS date value TRANSLATE(source,to,from) Replaces specific characters in a character expression SUM(argument,argument, ...) Returns the total value of the numeric arguments TRIM(argument) Takes the argument and removes any trailing blanks. UPCASE(argument) Converts all letters in an argument to uppercase WEEKDAY(date) Returns the day of the week from a SAS date value YEAR(date) Returns the year from a SAS date value SAS Formats w.d standard numeric COMMAw.d writes numeric values with commas and decimal points Zw.d print leading zeros $w. writes standard character data $CHARw. writes standard character data (including leading blanks) $VARYINGw. Writes character data of varying length SAS Informats w.d Reads standard numeric data datew. Reads date values (ddmmmyy) $w. Reads standard character data $VARYINGw. Reads character data of varying length Compliments of: David Franklin New Hampshire, USA Tel/Fax +1(603) 262-9160 Cell +1(603) 275-6809 Email 100316.3451@compuserve.com Google “Franklin SAS” http://ourworld.compuserve.com/homepages/dfranklinuk Release 1.2b ©MMVII
  • 2. SAS® Cheat Sheet SAS Procedures PROC COMPARE <BASE=dset> <COMPARE=dset>; BY variable(s); ID variable(s); VAR variable(s); PROC DATASETS <LIBRARY=libref> <MEMTYPE=(m-list)> <DETAILS|NODETAILS> <KILL> <NOLIST>; APPEND BASE=dset <DATA=dset> <FORCE>; CHANGE old-namen=new-namen </MEMTYPE=(m-list); CONTENTS <DATA=<libref.>member> <DIRECTORY> <MEMTYPE=(m-list)> <NODS> <VARNUM> <NOPRINT> <OUT=dset>; COPY OUT=libref <IN=libref> <MEMTYPE=(m-list)> <MOVE>; EXCLUDE member-list </MEMTYPE=mtype>; SELECT member-list </MEMTYPE=mtype>; DELETE member-list </ MEMTYPE=mtype>; MODIFY member-name <(<LABEL=’data-set-label’|’ ‘> <SORTEDBY=sort-information>)>; FORMAT variable-format-name.; INDEX CREATE variable </<UNIQUE> <NOMISS>>; INDEX CREATE index=(variable-list) </<UNIQUE> <NOMISS>>; INDEX DELETE index-list; LABEL variable=’label-text’; RENAME variablen=new-variablen; QUIT; where m-list one or more of the member types that processing should be restricted to. member-list list of members in the directory to process. mtype restricts processing to one member type. PROC EXPORT DATA=<libref.>dset OUTFILE="filename" <REPLACE>; PROC IMPORT DATAFILE="filename" OUT=<libref.>dset <REPLACE>; The following filetypes are the most commonly used and supported within filename by SAS: filename.XLS (Microsoft Excel) filename.TXT (tab delimited) filename.CSV (comma separated value) PROC FORMAT <CNTLIN=dset> <CNTLOUT=dset> <LIBRARY=libref<.catalog>>; INVALUE <$>name <value-range-set(s)>; PICTURE name <...value-range-set <(picture-option(s))>>; VALUE <$>name <value-range-set>; where picture-options The following options are useful: ROUND NOEDIT PREFIX= FILL= PROC FREQ <DATA=dset> <ORDER=DATA|EXTERNAL|FREQ|INTERNAL>; BY <DESCENDING> varn; TABLES requests </tables-options>; where requests one or more variable names joined by asterisks that specify the form of the generated tables, e.g. A*B tables-options Can be one or more of the following: LIST MISSING NOPRINT OUT=SAS-data-set OUTPCT SPARSE PROC MEANS <DATA=dset> <DESCENDING> <MISSING> <NOPRINT> <NWAY> <ORDER=DATA|EXTERNAL|FREQ| INTERNAL> <statistic-list>; VAR variable-list; CLASS variable-list; OUTPUT <OUT=dset> <out-statistic>; where statistic-list Can be one or more of the following: N, NMISS, MIN, MAX, RANGE, MEDIAN, SUM, MEAN, VAR, STD, Q1, Q3, T out-statistic Specifies the statistics in the output and also names the variable(s) that contain the results. PROC REPORT <DATA=dset> <HEADLINE> <HEADSKIP> <NOWINDOWS> <SPACING=number>; COLUMNS <report-item1, <., report-itemn>> (`header1 ' < . `headern '> report-item(s) ); DEFINE report-item / <usage> <define-options>; COMPUTE <BEFORE|AFTER> report-item; LINE <item item-format | 'text' | pointer-control>; ENDCOMP; BREAK BEFORE|AFTER break-variable </b-option(s)>; QUIT; where report-item name or alias (established in the COLUMN statement) of the data set or computed variable, or statistic to define usage Either ACROSS, ANALYSIS, COMPUTED, DISPLAY, GROUP, ORDER define-options The following options are available: FORMAT=format ORDER= SPACING= WIDTH= DESCENDING FLOW NOPRINT CENTER LEFT RIGHT COLOR= ‘column-header’ b-options These include: SKIP PAGE PROC SORT <DATA=dset> <OUT=dset> <NODUPKEY|NODUPS>; BY <DESCENDING> variable-list; PROC TRANSPOSE <DATA=dset> <OUT=dset>; BY <DESCENDING> variable-list; ID variable; VAR variable1 … variablen; Macro Language %DO macro-var=start_value %TO end_value <%BY step>; Executes a section of a macro repetitively based on the value of an index variable %DO %WHILE (expression); Executes a section of a macro repetitively while a condition is true %DO %UNTIL (expression); Executes a section of a macro repetitively until a condition is true %GLOBAL macro-variable(s); Creates macro variables that are available during the execution of an entire SAS session %IF expression %THEN action; <%ELSE action;> Conditionally process a portion of a macro %LENGTH (character string | text expression) Returns the length of a string %LET macro-variable =<value>; Creates a macro variable and assigns it a value %MACRO m-name (<pp1><…,ppn><kp1=value<..<kpn=v>); Begins a macro definition %MEND <macro-name>; Ends a macro definition %SCAN(argumentn<,delimiters>) Search for a word that is specified by its position in a string %SUBSTR(argument,position<,length>) Produce a substring of a character string %UPCASE(character string | text expression) Convert values to uppercase Macro Quoting %QUOTE | %NRQUOTE and %BQUOTE | %NRBQUOTE Mask special characters and mnemonic operators in a resolved value at macro execution %STR | %NRSTR Mask special characters and mnemonic operators in constant text at macro compilation %SUPERQ Masks special characters/mnemonic operators at macro execution but prevents further resolution of the value. Compliments of: David Franklin New Hampshire, USA Tel/Fax +1(603) 262-9160 Cell +1(603) 275-6809 Email 100316.3451@compuserve.com Google “Franklin SAS” http://ourworld.compuserve.com/homepages/dfranklinuk Release 1.2b ©MMVII